home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / dbxread.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  158KB  |  5,442 lines

  1. /* Read dbx symbol tables and convert to internal format, for GDB.
  2.    Copyright (C) 1986-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* This module provides three functions: dbx_symfile_init,
  21.    which initializes to read a symbol file; dbx_new_init, which 
  22.    discards existing cached information when all symbols are being
  23.    discarded; and dbx_symfile_read, which reads a symbol table
  24.    from a file.
  25.  
  26.    dbx_symfile_read only does the minimum work necessary for letting the
  27.    user "name" things symbolically; it does not read the entire symtab.
  28.    Instead, it reads the external and static symbols and puts them in partial
  29.    symbol tables.  When more extensive information is requested of a
  30.    file, the corresponding partial symbol table is mutated into a full
  31.    fledged symbol table by going back and reading the symbols
  32.    for real.  dbx_psymtab_to_symtab() is the function that does this */
  33.  
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include "defs.h"
  37. #include "param.h"
  38.  
  39. #ifdef USG
  40. #include <sys/types.h>
  41. #include <fcntl.h>
  42. #define L_SET 0
  43. #define L_INCR 1
  44. #endif
  45.  
  46. #include <obstack.h>
  47. #include <sys/param.h>
  48. #include <sys/file.h>
  49. #include <sys/stat.h>
  50. #include <ctype.h>
  51. #include "symtab.h"
  52. #include "breakpoint.h"
  53. #include "command.h"
  54. #include "target.h"
  55. #include "gdbcore.h"        /* for bfd stuff */
  56. #include "libaout.h"         /* FIXME Secret internal BFD stuff for a.out */
  57. #include "symfile.h"
  58.  
  59. #include "aout64.h"
  60. #include "stab.gnu.h"        /* We always use GNU stabs, not native, now */
  61.  
  62. #ifndef NO_GNU_STABS
  63. /*
  64.  * Define specifically gnu symbols here.
  65.  */
  66.  
  67. /* The following type indicates the definition of a symbol as being
  68.    an indirect reference to another symbol.  The other symbol
  69.    appears as an undefined reference, immediately following this symbol.
  70.  
  71.    Indirection is asymmetrical.  The other symbol's value will be used
  72.    to satisfy requests for the indirect symbol, but not vice versa.
  73.    If the other symbol does not have a definition, libraries will
  74.    be searched to find a definition.  */
  75. #ifndef N_INDR
  76. #define N_INDR 0xa
  77. #endif
  78.  
  79. /* The following symbols refer to set elements.
  80.    All the N_SET[ATDB] symbols with the same name form one set.
  81.    Space is allocated for the set in the text section, and each set
  82.    element's value is stored into one word of the space.
  83.    The first word of the space is the length of the set (number of elements).
  84.  
  85.    The address of the set is made into an N_SETV symbol
  86.    whose name is the same as the name of the set.
  87.    This symbol acts like a N_DATA global symbol
  88.    in that it can satisfy undefined external references.  */
  89.  
  90. #ifndef N_SETA
  91. #define    N_SETA    0x14        /* Absolute set element symbol */
  92. #endif                /* This is input to LD, in a .o file.  */
  93.  
  94. #ifndef N_SETT
  95. #define    N_SETT    0x16        /* Text set element symbol */
  96. #endif                /* This is input to LD, in a .o file.  */
  97.  
  98. #ifndef N_SETD
  99. #define    N_SETD    0x18        /* Data set element symbol */
  100. #endif                /* This is input to LD, in a .o file.  */
  101.  
  102. #ifndef N_SETB
  103. #define    N_SETB    0x1A        /* Bss set element symbol */
  104. #endif                /* This is input to LD, in a .o file.  */
  105.  
  106. /* Macros dealing with the set element symbols defined in a.out.h */
  107. #define    SET_ELEMENT_P(x)    ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT))
  108. #define TYPE_OF_SET_ELEMENT(x)    ((x)-N_SETA+N_ABS)
  109.  
  110. #ifndef N_SETV
  111. #define N_SETV    0x1C        /* Pointer to set vector in data area.  */
  112. #endif                /* This is output from LD.  */
  113.  
  114. #ifndef N_WARNING
  115. #define N_WARNING 0x1E        /* Warning message to print if file included */
  116. #endif                /* This is input to ld */
  117.  
  118. #endif /* NO_GNU_STABS */
  119.  
  120. struct dbx_symfile_info {
  121.   asection *text_sect;        /* Text section accessor */
  122.   int symcount;            /* How many symbols are there in the file */
  123.   char *stringtab;        /* The actual string table */
  124.   int stringtab_size;        /* Its size */
  125.   off_t symtab_offset;        /* Offset in file to symbol table */
  126.   int desc;            /* File descriptor of symbol file */
  127. };
  128.  
  129. extern void qsort ();
  130. extern double atof ();
  131. extern struct cmd_list_element *cmdlist;
  132.  
  133. extern void symbol_file_command ();
  134.  
  135. /* Forward declarations */
  136.  
  137. static void add_symbol_to_list ();
  138. static void read_dbx_symtab ();
  139. static void init_psymbol_list ();
  140. static void process_one_symbol ();
  141. static struct type *read_type ();
  142. static struct type *read_range_type ();
  143. static struct type *read_enum_type ();
  144. static struct type *read_struct_type ();
  145. static struct type *read_array_type ();
  146. static long read_number ();
  147. static void finish_block ();
  148. static struct blockvector *make_blockvector ();
  149. static struct symbol *define_symbol ();
  150. static void start_subfile ();
  151. static int hashname ();
  152. static struct pending *copy_pending ();
  153. static void fix_common_block ();
  154. static void add_undefined_type ();
  155. static void cleanup_undefined_types ();
  156. static void scan_file_globals ();
  157. static struct symtab *read_ofile_symtab ();
  158. static void dbx_psymtab_to_symtab ();
  159.  
  160. /* C++ */
  161. static struct type **read_args ();
  162.  
  163. static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
  164. static const char vb_name[] =   { '_','v','b',CPLUS_MARKER,'\0' };
  165.  
  166. /* Macro to determine which symbols to ignore when reading the first symbol
  167.    of a file.  Some machines override this definition. */
  168. #ifndef IGNORE_SYMBOL
  169. /* This code is used on Ultrix systems.  Ignore it */
  170. #define IGNORE_SYMBOL(type)  (type == (int)N_NSYMS)
  171. #endif
  172.  
  173. /* Macro for name of symbol to indicate a file compiled with gcc. */
  174. #ifndef GCC_COMPILED_FLAG_SYMBOL
  175. #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
  176. #endif
  177.  
  178. /* Convert stab register number (from `r' declaration) to a gdb REGNUM.  */
  179.  
  180. #ifndef STAB_REG_TO_REGNUM
  181. #define STAB_REG_TO_REGNUM(VALUE) (VALUE)
  182. #endif
  183.  
  184. /* Define this as 1 if a pcc declaration of a char or short argument
  185.    gives the correct address.  Otherwise assume pcc gives the
  186.    address of the corresponding int, which is not the same on a
  187.    big-endian machine.  */
  188.  
  189. #ifndef BELIEVE_PCC_PROMOTION
  190. #define BELIEVE_PCC_PROMOTION 0
  191. #endif
  192.  
  193. /* Nonzero means give verbose info on gdb action.  From main.c.  */
  194. extern int info_verbose;
  195.  
  196. /* Name of source file whose symbol data we are now processing.
  197.    This comes from a symbol of type N_SO.  */
  198.  
  199. static char *last_source_file;
  200.  
  201. /* Core address of start of text of current source file.
  202.    This too comes from the N_SO symbol.  */
  203.  
  204. static CORE_ADDR last_source_start_addr;
  205.  
  206. /* The entry point of a file we are reading.  */
  207. CORE_ADDR entry_point;
  208.  
  209. /* The list of sub-source-files within the current individual compilation.
  210.    Each file gets its own symtab with its own linetable and associated info,
  211.    but they all share one blockvector.  */
  212.  
  213. struct subfile
  214. {
  215.   struct subfile *next;
  216.   char *name;
  217.   char *dirname;
  218.   struct linetable *line_vector;
  219.   int line_vector_length;
  220.   int line_vector_index;
  221.   int prev_line_number;
  222. };
  223.  
  224. static struct subfile *subfiles;
  225.  
  226. static struct subfile *current_subfile;
  227.  
  228. /* Count symbols as they are processed, for error messages.  */
  229.  
  230. static unsigned int symnum;
  231.  
  232. /* Vector of types defined so far, indexed by their dbx type numbers.
  233.    (In newer sun systems, dbx uses a pair of numbers in parens,
  234.     as in "(SUBFILENUM,NUMWITHINSUBFILE)".  Then these numbers must be
  235.     translated through the type_translations hash table to get
  236.     the index into the type vector.)  */
  237.  
  238. static struct type **type_vector;
  239.  
  240. /* Number of elements allocated for type_vector currently.  */
  241.  
  242. static int type_vector_length;
  243.  
  244. /* Vector of line number information.  */
  245.  
  246. static struct linetable *line_vector;
  247.  
  248. /* Index of next entry to go in line_vector_index.  */
  249.  
  250. static int line_vector_index;
  251.  
  252. /* Last line number recorded in the line vector.  */
  253.  
  254. static int prev_line_number;
  255.  
  256. /* Number of elements allocated for line_vector currently.  */
  257.  
  258. static int line_vector_length;
  259.  
  260. /* Hash table of global symbols whose values are not known yet.
  261.    They are chained thru the SYMBOL_VALUE_CHAIN, since we don't
  262.    have the correct data for that slot yet.  */
  263. /* The use of the LOC_BLOCK code in this chain is nonstandard--
  264.    it refers to a FORTRAN common block rather than the usual meaning.  */
  265.  
  266. #define HASHSIZE 127
  267. static struct symbol *global_sym_chain[HASHSIZE];
  268.  
  269. /* Record the symbols defined for each context in a list.
  270.    We don't create a struct block for the context until we
  271.    know how long to make it.  */
  272.  
  273. #define PENDINGSIZE 100
  274.  
  275. struct pending
  276. {
  277.   struct pending *next;
  278.   int nsyms;
  279.   struct symbol *symbol[PENDINGSIZE];
  280. };
  281.  
  282. /* List of free `struct pending' structures for reuse.  */
  283. struct pending *free_pendings;
  284.  
  285. /* Here are the three lists that symbols are put on.  */
  286.  
  287. struct pending *file_symbols;    /* static at top level, and types */
  288.  
  289. struct pending *global_symbols;    /* global functions and variables */
  290.  
  291. struct pending *local_symbols;    /* everything local to lexical context */
  292.  
  293. /* List of symbols declared since the last BCOMM.  This list is a tail
  294.    of local_symbols.  When ECOMM is seen, the symbols on the list
  295.    are noted so their proper addresses can be filled in later,
  296.    using the common block base address gotten from the assembler
  297.    stabs.  */
  298.  
  299. struct pending *common_block;
  300. int common_block_i;
  301.  
  302. /* Stack representing unclosed lexical contexts
  303.    (that will become blocks, eventually).  */
  304.  
  305. struct context_stack
  306. {
  307.   struct pending *locals;
  308.   struct pending_block *old_blocks;
  309.   struct symbol *name;
  310.   CORE_ADDR start_addr;
  311.   CORE_ADDR end_addr;        /* Temp slot for exception handling. */
  312.   int depth;
  313. };
  314.  
  315. struct context_stack *context_stack;
  316.  
  317. /* Index of first unused entry in context stack.  */
  318. int context_stack_depth;
  319.  
  320. /* Currently allocated size of context stack.  */
  321.  
  322. int context_stack_size;
  323.  
  324. /* Nonzero if within a function (so symbols should be local,
  325.    if nothing says specifically).  */
  326.  
  327. int within_function;
  328.  
  329. #if 0
  330. /* The type of the function we are currently reading in.  This is
  331.    used by define_symbol to record the type of arguments to a function. */
  332.  
  333. static struct type *in_function_type;
  334. #endif
  335.  
  336. /* List of blocks already made (lexical contexts already closed).
  337.    This is used at the end to make the blockvector.  */
  338.  
  339. struct pending_block
  340. {
  341.   struct pending_block *next;
  342.   struct block *block;
  343. };
  344.  
  345. struct pending_block *pending_blocks;
  346.  
  347. extern CORE_ADDR startup_file_start;    /* From blockframe.c */
  348. extern CORE_ADDR startup_file_end;    /* From blockframe.c */
  349.  
  350. /* Global variable which, when set, indicates that we are processing a
  351.    .o file compiled with gcc */
  352.  
  353. static unsigned char processing_gcc_compilation;
  354.  
  355. /* Make a list of forward references which haven't been defined.  */
  356. static struct type **undef_types;
  357. static int undef_types_allocated, undef_types_length;
  358.  
  359. /* String table for the main symbol file.  It is kept in memory
  360.    permanently, to speed up symbol reading.  Other files' symbol tables
  361.    are read in on demand.  FIXME, this should be cleaner.  */
  362.  
  363. static char *symfile_string_table;
  364. static int symfile_string_table_size;
  365.  
  366. /* The size of each symbol in the symbol file (in external form).
  367.    This is set by dbx_symfile_read when building psymtabs, and by
  368.    dbx_psymtab_to_symtab when building symtabs.  */
  369.  
  370. static unsigned symbol_size;
  371.  
  372. /* Setup a define to deal cleanly with the underscore problem */
  373.  
  374. #ifdef NAMES_HAVE_UNDERSCORE
  375. #define HASH_OFFSET 1
  376. #else
  377. #define HASH_OFFSET 0
  378. #endif
  379.  
  380. /* Complaints about the symbols we have encountered.  */
  381.  
  382. struct complaint innerblock_complaint =
  383.   {"inner block not inside outer block in %s", 0, 0};
  384.  
  385. struct complaint blockvector_complaint = 
  386.   {"block at %x out of order", 0, 0};
  387.  
  388. struct complaint lbrac_complaint = 
  389.   {"bad block start address patched", 0, 0};
  390.  
  391. #if 0
  392. struct complaint dbx_class_complaint =
  393.   {"encountered DBX-style class variable debugging information.\n\
  394. You seem to have compiled your program with \
  395. \"g++ -g0\" instead of \"g++ -g\".\n\
  396. Therefore GDB will not know about your class variables", 0, 0};
  397. #endif
  398.  
  399. struct complaint string_table_offset_complaint =
  400.   {"bad string table offset in symbol %d", 0, 0};
  401.  
  402. struct complaint unknown_symtype_complaint =
  403.   {"unknown symbol type %s", 0, 0};
  404.  
  405. struct complaint lbrac_rbrac_complaint =
  406.   {"block start larger than block end", 0, 0};
  407.  
  408. struct complaint const_vol_complaint =
  409.   {"const/volatile indicator missing (ok if using g++ v1.x), got '%c'", 0, 0};
  410.  
  411. struct complaint error_type_complaint =
  412.   {"debug info mismatch between compiler and debugger", 0, 0};
  413.  
  414. struct complaint invalid_member_complaint =
  415.   {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
  416.  
  417. struct complaint range_type_base_complaint =
  418.   {"base type %d of range type is not defined", 0, 0};
  419.  
  420. /* Support for Sun changes to dbx symbol format */
  421.  
  422. /* For each identified header file, we have a table of types defined
  423.    in that header file.
  424.  
  425.    header_files maps header file names to their type tables.
  426.    It is a vector of n_header_files elements.
  427.    Each element describes one header file.
  428.    It contains a vector of types.
  429.  
  430.    Sometimes it can happen that the same header file produces
  431.    different results when included in different places.
  432.    This can result from conditionals or from different
  433.    things done before including the file.
  434.    When this happens, there are multiple entries for the file in this table,
  435.    one entry for each distinct set of results.
  436.    The entries are distinguished by the INSTANCE field.
  437.    The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
  438.    used to match header-file references to their corresponding data.  */
  439.  
  440. struct header_file
  441. {
  442.   char *name;            /* Name of header file */
  443.   int instance;            /* Numeric code distinguishing instances
  444.                    of one header file that produced
  445.                    different results when included.
  446.                    It comes from the N_BINCL or N_EXCL.  */
  447.   struct type **vector;        /* Pointer to vector of types */
  448.   int length;            /* Allocated length (# elts) of that vector */
  449. };
  450.  
  451. static struct header_file *header_files = 0;
  452.  
  453. static int n_header_files;
  454.  
  455. static int n_allocated_header_files;
  456.  
  457. /* During initial symbol readin, we need to have a structure to keep
  458.    track of which psymtabs have which bincls in them.  This structure
  459.    is used during readin to setup the list of dependencies within each
  460.    partial symbol table. */
  461.  
  462. struct header_file_location
  463. {
  464.   char *name;            /* Name of header file */
  465.   int instance;            /* See above */
  466.   struct partial_symtab *pst;    /* Partial symtab that has the
  467.                    BINCL/EINCL defs for this file */
  468. };
  469.  
  470. /* The actual list and controling variables */
  471. static struct header_file_location *bincl_list, *next_bincl;
  472. static int bincls_allocated;
  473.  
  474. /* Within each object file, various header files are assigned numbers.
  475.    A type is defined or referred to with a pair of numbers
  476.    (FILENUM,TYPENUM) where FILENUM is the number of the header file
  477.    and TYPENUM is the number within that header file.
  478.    TYPENUM is the index within the vector of types for that header file.
  479.  
  480.    FILENUM == 1 is special; it refers to the main source of the object file,
  481.    and not to any header file.  FILENUM != 1 is interpreted by looking it up
  482.    in the following table, which contains indices in header_files.  */
  483.  
  484. static int *this_object_header_files = 0;
  485.  
  486. static int n_this_object_header_files;
  487.  
  488. static int n_allocated_this_object_header_files;
  489.  
  490. /* When a header file is getting special overriding definitions
  491.    for one source file, record here the header_files index
  492.    of its normal definition vector.
  493.    At other times, this is -1.  */
  494.  
  495. static int header_file_prev_index;
  496.  
  497. /* Free up old header file tables, and allocate new ones.
  498.    We're reading a new symbol file now.  */
  499.  
  500. static void
  501. free_and_init_header_files ()
  502. {
  503.   register int i;
  504.   for (i = 0; i < n_header_files; i++)
  505.     free (header_files[i].name);
  506.   if (header_files)            /* First time null */
  507.     free (header_files);
  508.   if (this_object_header_files)        /* First time null */
  509.     free (this_object_header_files);
  510.  
  511.   n_allocated_header_files = 10;
  512.   header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file));
  513.   n_header_files = 0;
  514.  
  515.   n_allocated_this_object_header_files = 10;
  516.   this_object_header_files = (int *) xmalloc (10 * sizeof (int));
  517. }
  518.  
  519. /* Called at the start of each object file's symbols.
  520.    Clear out the mapping of header file numbers to header files.  */
  521.  
  522. static void
  523. new_object_header_files ()
  524. {
  525.   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
  526.   n_this_object_header_files = 1;
  527.   header_file_prev_index = -1;
  528. }
  529.  
  530. /* Add header file number I for this object file
  531.    at the next successive FILENUM.  */
  532.  
  533. static void
  534. add_this_object_header_file (i)
  535.      int i;
  536. {
  537.   if (n_this_object_header_files == n_allocated_this_object_header_files)
  538.     {
  539.       n_allocated_this_object_header_files *= 2;
  540.       this_object_header_files
  541.     = (int *) xrealloc (this_object_header_files,
  542.                 n_allocated_this_object_header_files * sizeof (int));
  543.     }
  544.  
  545.   this_object_header_files[n_this_object_header_files++] = i;
  546. }
  547.  
  548. /* Add to this file an "old" header file, one already seen in
  549.    a previous object file.  NAME is the header file's name.
  550.    INSTANCE is its instance code, to select among multiple
  551.    symbol tables for the same header file.  */
  552.  
  553. static void
  554. add_old_header_file (name, instance)
  555.      char *name;
  556.      int instance;
  557. {
  558.   register struct header_file *p = header_files;
  559.   register int i;
  560.  
  561.   for (i = 0; i < n_header_files; i++)
  562.     if (!strcmp (p[i].name, name) && instance == p[i].instance)
  563.       {
  564.     add_this_object_header_file (i);
  565.     return;
  566.       }
  567.   error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
  568.      symnum);
  569. }
  570.  
  571. /* Add to this file a "new" header file: definitions for its types follow.
  572.    NAME is the header file's name.
  573.    Most often this happens only once for each distinct header file,
  574.    but not necessarily.  If it happens more than once, INSTANCE has
  575.    a different value each time, and references to the header file
  576.    use INSTANCE values to select among them.
  577.  
  578.    dbx output contains "begin" and "end" markers for each new header file,
  579.    but at this level we just need to know which files there have been;
  580.    so we record the file when its "begin" is seen and ignore the "end".  */
  581.  
  582. static void
  583. add_new_header_file (name, instance)
  584.      char *name;
  585.      int instance;
  586. {
  587.   register int i;
  588.   header_file_prev_index = -1;
  589.  
  590.   /* Make sure there is room for one more header file.  */
  591.  
  592.   if (n_header_files == n_allocated_header_files)
  593.     {
  594.       n_allocated_header_files *= 2;
  595.       header_files = (struct header_file *)
  596.     xrealloc (header_files,
  597.           (n_allocated_header_files
  598.            * sizeof (struct header_file)));
  599.     }
  600.  
  601.   /* Create an entry for this header file.  */
  602.  
  603.   i = n_header_files++;
  604.   header_files[i].name = savestring (name, strlen(name));
  605.   header_files[i].instance = instance;
  606.   header_files[i].length = 10;
  607.   header_files[i].vector
  608.     = (struct type **) xmalloc (10 * sizeof (struct type *));
  609.   bzero (header_files[i].vector, 10 * sizeof (struct type *));
  610.  
  611.   add_this_object_header_file (i);
  612. }
  613.  
  614. /* Look up a dbx type-number pair.  Return the address of the slot
  615.    where the type for that number-pair is stored.
  616.    The number-pair is in TYPENUMS.
  617.  
  618.    This can be used for finding the type associated with that pair
  619.    or for associating a new type with the pair.  */
  620.  
  621. static struct type **
  622. dbx_lookup_type (typenums)
  623.      int typenums[2];
  624. {
  625.   register int filenum = typenums[0], index = typenums[1];
  626.  
  627.   if (filenum < 0 || filenum >= n_this_object_header_files)
  628.     error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
  629.        filenum, index, symnum);
  630.  
  631.   if (filenum == 0)
  632.     {
  633.       /* Type is defined outside of header files.
  634.      Find it in this object file's type vector.  */
  635.       while (index >= type_vector_length)
  636.     {
  637.       type_vector_length *= 2;
  638.       type_vector = (struct type **)
  639.         xrealloc (type_vector,
  640.               (type_vector_length * sizeof (struct type *)));
  641.       bzero (&type_vector[type_vector_length / 2],
  642.          type_vector_length * sizeof (struct type *) / 2);
  643.     }
  644.       return &type_vector[index];
  645.     }
  646.   else
  647.     {
  648.       register int real_filenum = this_object_header_files[filenum];
  649.       register struct header_file *f;
  650.       int f_orig_length;
  651.  
  652.       if (real_filenum >= n_header_files)
  653.     abort ();
  654.  
  655.       f = &header_files[real_filenum];
  656.  
  657.       f_orig_length = f->length;
  658.       if (index >= f_orig_length)
  659.     {
  660.       while (index >= f->length)
  661.         f->length *= 2;
  662.       f->vector = (struct type **)
  663.         xrealloc (f->vector, f->length * sizeof (struct type *));
  664.       bzero (&f->vector[f_orig_length],
  665.          (f->length - f_orig_length) * sizeof (struct type *));
  666.     }
  667.       return &f->vector[index];
  668.     }
  669. }
  670.  
  671. /* Create a type object.  Occaisionally used when you need a type
  672.    which isn't going to be given a type number.  */
  673.  
  674. static struct type *
  675. dbx_create_type ()
  676. {
  677.   register struct type *type =
  678.     (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type));
  679.  
  680.   bzero (type, sizeof (struct type));
  681.   TYPE_VPTR_FIELDNO (type) = -1;
  682.   TYPE_VPTR_BASETYPE (type) = 0;
  683.   return type;
  684. }
  685.  
  686. /* Make sure there is a type allocated for type numbers TYPENUMS
  687.    and return the type object.
  688.    This can create an empty (zeroed) type object.
  689.    TYPENUMS may be (-1, -1) to return a new type object that is not
  690.    put into the type vector, and so may not be referred to by number. */
  691.  
  692. static struct type *
  693. dbx_alloc_type (typenums)
  694.      int typenums[2];
  695. {
  696.   register struct type **type_addr;
  697.   register struct type *type;
  698.  
  699.   if (typenums[1] != -1)
  700.     {
  701.       type_addr = dbx_lookup_type (typenums);
  702.       type = *type_addr;
  703.     }
  704.   else
  705.     {
  706.       type_addr = 0;
  707.       type = 0;
  708.     }
  709.  
  710.   /* If we are referring to a type not known at all yet,
  711.      allocate an empty type for it.
  712.      We will fill it in later if we find out how.  */
  713.   if (type == 0)
  714.     {
  715.       type = dbx_create_type ();
  716.       if (type_addr)
  717.     *type_addr = type;
  718.     }
  719.   
  720.   return type;
  721. }
  722.  
  723. #if 0
  724. static struct type **
  725. explicit_lookup_type (real_filenum, index)
  726.      int real_filenum, index;
  727. {
  728.   register struct header_file *f = &header_files[real_filenum];
  729.  
  730.   if (index >= f->length)
  731.     {
  732.       f->length *= 2;
  733.       f->vector = (struct type **)
  734.     xrealloc (f->vector, f->length * sizeof (struct type *));
  735.       bzero (&f->vector[f->length / 2],
  736.          f->length * sizeof (struct type *) / 2);
  737.     }
  738.   return &f->vector[index];
  739. }
  740. #endif
  741.  
  742. /* maintain the lists of symbols and blocks */
  743.  
  744. /* Add a symbol to one of the lists of symbols.  */
  745. static void
  746. add_symbol_to_list (symbol, listhead)
  747.      struct symbol *symbol;
  748.      struct pending **listhead;
  749. {
  750.   /* We keep PENDINGSIZE symbols in each link of the list.
  751.      If we don't have a link with room in it, add a new link.  */
  752.   if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
  753.     {
  754.       register struct pending *link;
  755.       if (free_pendings)
  756.     {
  757.       link = free_pendings;
  758.       free_pendings = link->next;
  759.     }
  760.       else
  761.     link = (struct pending *) xmalloc (sizeof (struct pending));
  762.  
  763.       link->next = *listhead;
  764.       *listhead = link;
  765.       link->nsyms = 0;
  766.     }
  767.  
  768.   (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
  769. }
  770.  
  771. /* At end of reading syms, or in case of quit,
  772.    really free as many `struct pending's as we can easily find.  */
  773.  
  774. /* ARGSUSED */
  775. static void
  776. really_free_pendings (foo)
  777.      int foo;
  778. {
  779.   struct pending *next, *next1;
  780. #if 0
  781.   struct pending_block *bnext, *bnext1;
  782. #endif
  783.  
  784.   for (next = free_pendings; next; next = next1)
  785.     {
  786.       next1 = next->next;
  787.       free (next);
  788.     }
  789.   free_pendings = 0;
  790.  
  791. #if 0 /* Now we make the links in the symbol_obstack, so don't free them.  */
  792.   for (bnext = pending_blocks; bnext; bnext = bnext1)
  793.     {
  794.       bnext1 = bnext->next;
  795.       free (bnext);
  796.     }
  797. #endif
  798.   pending_blocks = 0;
  799.  
  800.   for (next = file_symbols; next; next = next1)
  801.     {
  802.       next1 = next->next;
  803.       free (next);
  804.     }
  805.   file_symbols = 0;
  806.  
  807.   for (next = global_symbols; next; next = next1)
  808.     {
  809.       next1 = next->next;
  810.       free (next);
  811.     }
  812.   global_symbols = 0;
  813. }
  814.  
  815. /* Take one of the lists of symbols and make a block from it.
  816.    Keep the order the symbols have in the list (reversed from the input file).
  817.    Put the block on the list of pending blocks.  */
  818.  
  819. static void
  820. finish_block (symbol, listhead, old_blocks, start, end)
  821.      struct symbol *symbol;
  822.      struct pending **listhead;
  823.      struct pending_block *old_blocks;
  824.      CORE_ADDR start, end;
  825. {
  826.   register struct pending *next, *next1;
  827.   register struct block *block;
  828.   register struct pending_block *pblock;
  829.   struct pending_block *opblock;
  830.   register int i;
  831.  
  832.   /* Count the length of the list of symbols.  */
  833.  
  834.   for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next)
  835.     /*EMPTY*/;
  836.  
  837.   block = (struct block *) obstack_alloc (symbol_obstack,
  838.                       (sizeof (struct block)
  839.                        + ((i - 1)
  840.                           * sizeof (struct symbol *))));
  841.  
  842.   /* Copy the symbols into the block.  */
  843.  
  844.   BLOCK_NSYMS (block) = i;
  845.   for (next = *listhead; next; next = next->next)
  846.     {
  847.       register int j;
  848.       for (j = next->nsyms - 1; j >= 0; j--)
  849.     BLOCK_SYM (block, --i) = next->symbol[j];
  850.     }
  851.  
  852.   BLOCK_START (block) = start;
  853.   BLOCK_END (block) = end;
  854.   BLOCK_SUPERBLOCK (block) = 0;    /* Filled in when containing block is made */
  855.   BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
  856.  
  857.   /* Put the block in as the value of the symbol that names it.  */
  858.  
  859.   if (symbol)
  860.     {
  861.       SYMBOL_BLOCK_VALUE (symbol) = block;
  862.       BLOCK_FUNCTION (block) = symbol;
  863.     }
  864.   else
  865.     BLOCK_FUNCTION (block) = 0;
  866.  
  867.   /* Now "free" the links of the list, and empty the list.  */
  868.  
  869.   for (next = *listhead; next; next = next1)
  870.     {
  871.       next1 = next->next;
  872.       next->next = free_pendings;
  873.       free_pendings = next;
  874.     }
  875.   *listhead = 0;
  876.  
  877.   /* Install this block as the superblock
  878.      of all blocks made since the start of this scope
  879.      that don't have superblocks yet.  */
  880.  
  881.   opblock = 0;
  882.   for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
  883.     {
  884.       if (BLOCK_SUPERBLOCK (pblock->block) == 0) {
  885. #if 1
  886.     /* Check to be sure the blocks are nested as we receive them. 
  887.        If the compiler/assembler/linker work, this just burns a small
  888.        amount of time.  */
  889.     if (BLOCK_START (pblock->block) < BLOCK_START (block)
  890.      || BLOCK_END   (pblock->block) > BLOCK_END   (block)) {
  891.       complain(&innerblock_complaint, symbol? SYMBOL_NAME (symbol):
  892.                          "(don't know)");
  893.       BLOCK_START (pblock->block) = BLOCK_START (block);
  894.       BLOCK_END   (pblock->block) = BLOCK_END   (block);
  895.     }
  896. #endif
  897.     BLOCK_SUPERBLOCK (pblock->block) = block;
  898.       }
  899.       opblock = pblock;
  900.     }
  901.  
  902.   /* Record this block on the list of all blocks in the file.
  903.      Put it after opblock, or at the beginning if opblock is 0.
  904.      This puts the block in the list after all its subblocks.  */
  905.  
  906.   /* Allocate in the symbol_obstack to save time.
  907.      It wastes a little space.  */
  908.   pblock = (struct pending_block *)
  909.     obstack_alloc (symbol_obstack,
  910.            sizeof (struct pending_block));
  911.   pblock->block = block;
  912.   if (opblock)
  913.     {
  914.       pblock->next = opblock->next;
  915.       opblock->next = pblock;
  916.     }
  917.   else
  918.     {
  919.       pblock->next = pending_blocks;
  920.       pending_blocks = pblock;
  921.     }
  922. }
  923.  
  924. static struct blockvector *
  925. make_blockvector ()
  926. {
  927.   register struct pending_block *next;
  928.   register struct blockvector *blockvector;
  929.   register int i;
  930.  
  931.   /* Count the length of the list of blocks.  */
  932.  
  933.   for (next = pending_blocks, i = 0; next; next = next->next, i++);
  934.  
  935.   blockvector = (struct blockvector *)
  936.     obstack_alloc (symbol_obstack,
  937.            (sizeof (struct blockvector)
  938.             + (i - 1) * sizeof (struct block *)));
  939.  
  940.   /* Copy the blocks into the blockvector.
  941.      This is done in reverse order, which happens to put
  942.      the blocks into the proper order (ascending starting address).
  943.      finish_block has hair to insert each block into the list
  944.      after its subblocks in order to make sure this is true.  */
  945.  
  946.   BLOCKVECTOR_NBLOCKS (blockvector) = i;
  947.   for (next = pending_blocks; next; next = next->next) {
  948.     BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
  949.   }
  950.  
  951. #if 0 /* Now we make the links in the obstack, so don't free them.  */
  952.   /* Now free the links of the list, and empty the list.  */
  953.  
  954.   for (next = pending_blocks; next; next = next1)
  955.     {
  956.       next1 = next->next;
  957.       free (next);
  958.     }
  959. #endif
  960.   pending_blocks = 0;
  961.  
  962. #if 1  /* FIXME, shut this off after a while to speed up symbol reading.  */
  963.   /* Some compilers output blocks in the wrong order, but we depend
  964.      on their being in the right order so we can binary search. 
  965.      Check the order and moan about it.  FIXME.  */
  966.   if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
  967.     for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) {
  968.       if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
  969.       > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) {
  970.     complain (&blockvector_complaint, 
  971.       BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
  972.       }
  973.     }
  974. #endif
  975.  
  976.   return blockvector;
  977. }
  978.  
  979. /* Manage the vector of line numbers.  */
  980.  
  981. static void
  982. record_line (line, pc)
  983.      int line;
  984.      CORE_ADDR pc;
  985. {
  986.   struct linetable_entry *e;
  987.   /* Ignore the dummy line number in libg.o */
  988.  
  989.   if (line == 0xffff)
  990.     return;
  991.  
  992.   /* Make sure line vector is big enough.  */
  993.  
  994.   if (line_vector_index + 1 >= line_vector_length)
  995.     {
  996.       line_vector_length *= 2;
  997.       line_vector = (struct linetable *)
  998.     xrealloc (line_vector,
  999.           (sizeof (struct linetable)
  1000.            + line_vector_length * sizeof (struct linetable_entry)));
  1001.       current_subfile->line_vector = line_vector;
  1002.     }
  1003.  
  1004.   e = line_vector->item + line_vector_index++;
  1005.   e->line = line; e->pc = pc;
  1006. }
  1007.  
  1008. /* Start a new symtab for a new source file.
  1009.    This is called when a dbx symbol of type N_SO is seen;
  1010.    it indicates the start of data for one original source file.  */
  1011.  
  1012. static void
  1013. start_symtab (name, dirname, start_addr)
  1014.      char *name;
  1015.      char *dirname;
  1016.      CORE_ADDR start_addr;
  1017. {
  1018.  
  1019.   last_source_file = name;
  1020.   last_source_start_addr = start_addr;
  1021.   file_symbols = 0;
  1022.   global_symbols = 0;
  1023.   within_function = 0;
  1024.  
  1025.   /* Context stack is initially empty, with room for 10 levels.  */
  1026.   context_stack
  1027.     = (struct context_stack *) xmalloc (10 * sizeof (struct context_stack));
  1028.   context_stack_size = 10;
  1029.   context_stack_depth = 0;
  1030.  
  1031.   new_object_header_files ();
  1032.  
  1033.   type_vector_length = 160;
  1034.   type_vector = (struct type **)
  1035.     xmalloc (type_vector_length * sizeof (struct type *));
  1036.   bzero (type_vector, type_vector_length * sizeof (struct type *));
  1037.  
  1038.   /* Initialize the list of sub source files with one entry
  1039.      for this file (the top-level source file).  */
  1040.  
  1041.   subfiles = 0;
  1042.   current_subfile = 0;
  1043.   start_subfile (name, dirname);
  1044. }
  1045.  
  1046. /* Handle an N_SOL symbol, which indicates the start of
  1047.    code that came from an included (or otherwise merged-in)
  1048.    source file with a different name.  */
  1049.  
  1050. static void
  1051. start_subfile (name, dirname)
  1052.      char *name;
  1053.      char *dirname;
  1054. {
  1055.   register struct subfile *subfile;
  1056.  
  1057.   /* Save the current subfile's line vector data.  */
  1058.  
  1059.   if (current_subfile)
  1060.     {
  1061.       current_subfile->line_vector_index = line_vector_index;
  1062.       current_subfile->line_vector_length = line_vector_length;
  1063.       current_subfile->prev_line_number = prev_line_number;
  1064.     }
  1065.  
  1066.   /* See if this subfile is already known as a subfile of the
  1067.      current main source file.  */
  1068.  
  1069.   for (subfile = subfiles; subfile; subfile = subfile->next)
  1070.     {
  1071.       if (!strcmp (subfile->name, name))
  1072.     {
  1073.       line_vector = subfile->line_vector;
  1074.       line_vector_index = subfile->line_vector_index;
  1075.       line_vector_length = subfile->line_vector_length;
  1076.       prev_line_number = subfile->prev_line_number;
  1077.       current_subfile = subfile;
  1078.       return;
  1079.     }
  1080.     }
  1081.  
  1082.   /* This subfile is not known.  Add an entry for it.  */
  1083.  
  1084.   line_vector_index = 0;
  1085.   line_vector_length = 1000;
  1086.   prev_line_number = -2;    /* Force first line number to be explicit */
  1087.   line_vector = (struct linetable *)
  1088.     xmalloc (sizeof (struct linetable)
  1089.           + line_vector_length * sizeof (struct linetable_entry));
  1090.  
  1091.   /* Make an entry for this subfile in the list of all subfiles
  1092.      of the current main source file.  */
  1093.  
  1094.   subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
  1095.   subfile->next = subfiles;
  1096.   subfile->name = obsavestring (name, strlen (name));
  1097.   if (dirname == NULL)
  1098.     subfile->dirname = NULL;
  1099.   else
  1100.     subfile->dirname = obsavestring (dirname, strlen (dirname));
  1101.   
  1102.   subfile->line_vector = line_vector;
  1103.   subfiles = subfile;
  1104.   current_subfile = subfile;
  1105. }
  1106.  
  1107. /* Finish the symbol definitions for one main source file,
  1108.    close off all the lexical contexts for that file
  1109.    (creating struct block's for them), then make the struct symtab
  1110.    for that file and put it in the list of all such.
  1111.  
  1112.    END_ADDR is the address of the end of the file's text.  */
  1113.  
  1114. static struct symtab *
  1115. end_symtab (end_addr)
  1116.      CORE_ADDR end_addr;
  1117. {
  1118.   register struct symtab *symtab;
  1119.   register struct blockvector *blockvector;
  1120.   register struct subfile *subfile;
  1121.   register struct linetable *lv;
  1122.   struct subfile *nextsub;
  1123.  
  1124.   /* Finish the lexical context of the last function in the file;
  1125.      pop the context stack.  */
  1126.  
  1127.   if (context_stack_depth > 0)
  1128.     {
  1129.       register struct context_stack *cstk;
  1130.       context_stack_depth--;
  1131.       cstk = &context_stack[context_stack_depth];
  1132.       /* Make a block for the local symbols within.  */
  1133.       finish_block (cstk->name, &local_symbols, cstk->old_blocks,
  1134.             cstk->start_addr, end_addr);
  1135.     }
  1136.  
  1137.   /* Cleanup any undefined types that have been left hanging around
  1138.      (this needs to be done before the finish_blocks so that
  1139.      file_symbols is still good).  */
  1140.   cleanup_undefined_types ();
  1141.  
  1142.   /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector.  */
  1143.   finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr);
  1144.   finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr);
  1145.   blockvector = make_blockvector ();
  1146.  
  1147.   current_subfile->line_vector_index = line_vector_index;
  1148.  
  1149.   /* Now create the symtab objects proper, one for each subfile.  */
  1150.   /* (The main file is the last one on the chain.)  */
  1151.  
  1152.   for (subfile = subfiles; subfile; subfile = nextsub)
  1153.     {
  1154.       symtab = allocate_symtab (subfile->name);
  1155.  
  1156.       /* Fill in its components.  */
  1157.       symtab->blockvector = blockvector;
  1158.       lv = subfile->line_vector;
  1159.       lv->nitems = subfile->line_vector_index;
  1160.       symtab->linetable = (struct linetable *)
  1161.     xrealloc (lv, (sizeof (struct linetable)
  1162.                + lv->nitems * sizeof (struct linetable_entry)));
  1163.  
  1164.       symtab->dirname = subfile->dirname;
  1165.  
  1166.       symtab->free_code = free_linetable;
  1167.       symtab->free_ptr = 0;
  1168.  
  1169.       /* There should never already be a symtab for this name, since
  1170.      any prev dups have been removed when the psymtab was read in.
  1171.        FIXME, there ought to be a way to check this here.  */
  1172.       /* FIXME blewit |= free_named_symtabs (symtab->filename);  */
  1173.  
  1174.       /* Link the new symtab into the list of such.  */
  1175.       symtab->next = symtab_list;
  1176.       symtab_list = symtab;
  1177.  
  1178.       nextsub = subfile->next;
  1179.       free (subfile);
  1180.     }
  1181.  
  1182.   free ((char *) type_vector);
  1183.   type_vector = 0;
  1184.   type_vector_length = -1;
  1185.   line_vector = 0;
  1186.   line_vector_length = -1;
  1187.   last_source_file = 0;
  1188.  
  1189.   return symtab;
  1190. }
  1191.  
  1192. /* Handle the N_BINCL and N_EINCL symbol types
  1193.    that act like N_SOL for switching source files
  1194.    (different subfiles, as we call them) within one object file,
  1195.    but using a stack rather than in an arbitrary order.  */
  1196.  
  1197. struct subfile_stack
  1198. {
  1199.   struct subfile_stack *next;
  1200.   char *name;
  1201.   int prev_index;
  1202. };
  1203.  
  1204. struct subfile_stack *subfile_stack;
  1205.  
  1206. static void
  1207. push_subfile ()
  1208. {
  1209.   register struct subfile_stack *tem
  1210.     = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
  1211.  
  1212.   tem->next = subfile_stack;
  1213.   subfile_stack = tem;
  1214.   if (current_subfile == 0 || current_subfile->name == 0)
  1215.     abort ();
  1216.   tem->name = current_subfile->name;
  1217.   tem->prev_index = header_file_prev_index;
  1218. }
  1219.  
  1220. static char *
  1221. pop_subfile ()
  1222. {
  1223.   register char *name;
  1224.   register struct subfile_stack *link = subfile_stack;
  1225.  
  1226.   if (link == 0)
  1227.     abort ();
  1228.  
  1229.   name = link->name;
  1230.   subfile_stack = link->next;
  1231.   header_file_prev_index = link->prev_index;
  1232.   free (link);
  1233.  
  1234.   return name;
  1235. }
  1236.  
  1237. static void
  1238. record_misc_function (name, address, type)
  1239.      char *name;
  1240.      CORE_ADDR address;
  1241.      int type;
  1242. {
  1243.   enum misc_function_type misc_type;
  1244.  
  1245.   switch (type &~ N_EXT) {
  1246.     case N_TEXT:  misc_type = mf_text; break;
  1247.     case N_DATA:  misc_type = mf_data; break;
  1248.     case N_BSS:   misc_type = mf_bss;  break;
  1249.     case N_ABS:   misc_type = mf_abs;  break;
  1250. #ifdef N_SETV
  1251.     case N_SETV:  misc_type = mf_data; break;
  1252. #endif
  1253.     default:      misc_type = mf_unknown; break;
  1254.   }
  1255.  
  1256.   prim_record_misc_function (obsavestring (name, strlen (name)),
  1257.                  address, misc_type);
  1258. }
  1259.  
  1260. /* The BFD for this file -- only good while we're actively reading
  1261.    symbols into a psymtab or a symtab.  */
  1262.  
  1263. static bfd *symfile_bfd;
  1264.  
  1265. /* Scan and build partial symbols for a symbol file.
  1266.    We have been initialized by a call to dbx_symfile_init, which 
  1267.    put all the relevant info into a "struct dbx_symfile_info"
  1268.    hung off the struct sym_fns SF.
  1269.  
  1270.    ADDR is the address relative to which the symbols in it are (e.g.
  1271.    the base address of the text segment).
  1272.    MAINLINE is true if we are reading the main symbol
  1273.    table (as opposed to a shared lib or dynamically loaded file).  */
  1274.  
  1275. static void
  1276. dbx_symfile_read (sf, addr, mainline)
  1277.      struct sym_fns *sf;
  1278.      CORE_ADDR addr;
  1279.      int mainline;    /* FIXME comments above */
  1280. {
  1281.   struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private);
  1282.   bfd *sym_bfd = sf->sym_bfd;
  1283.   int val;
  1284.   char *filename = bfd_get_filename (sym_bfd);
  1285.  
  1286.   val = lseek (info->desc, info->symtab_offset, L_SET);
  1287.   if (val < 0)
  1288.     perror_with_name (filename);
  1289.  
  1290.   /* If mainline, set global string table pointers, and reinitialize global
  1291.      partial symbol list.  */
  1292.   if (mainline) {
  1293.     symfile_string_table = info->stringtab;
  1294.     symfile_string_table_size = info->stringtab_size;
  1295.   }
  1296.  
  1297.   /* If we are reinitializing, or if we have never loaded syms yet, init */
  1298.   if (mainline || global_psymbols.size == 0 || static_psymbols.size == 0)
  1299.     init_psymbol_list (info->symcount);
  1300.  
  1301.   symfile_bfd = sym_bfd;        /* Kludge for SWAP_SYMBOL */
  1302.  
  1303.   /* FIXME POKING INSIDE BFD DATA STRUCTURES */
  1304.   symbol_size = obj_symbol_entry_size (sym_bfd);
  1305.  
  1306.   pending_blocks = 0;
  1307.   make_cleanup (really_free_pendings, 0);
  1308.  
  1309.   init_misc_bunches ();
  1310.   make_cleanup (discard_misc_bunches, 0);
  1311.  
  1312.   /* Now that the symbol table data of the executable file are all in core,
  1313.      process them and define symbols accordingly.  */
  1314.  
  1315.   read_dbx_symtab (filename, 
  1316.            addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
  1317.            info->desc, info->stringtab, info->stringtab_size,
  1318.            info->symcount,
  1319.            bfd_section_vma  (sym_bfd, info->text_sect),
  1320.            bfd_section_size (sym_bfd, info->text_sect));
  1321.  
  1322.   /* Go over the misc symbol bunches and install them in vector.  */
  1323.  
  1324.   condense_misc_bunches (!mainline);
  1325.  
  1326.   /* Free up any memory we allocated for ourselves.  */
  1327.  
  1328.   if (!mainline) {
  1329.     free (info->stringtab);    /* Stringtab is only saved for mainline */
  1330.   }
  1331.   free (info);
  1332.   sf->sym_private = 0;        /* Zap pointer to our (now gone) info struct */
  1333.  
  1334. /*
  1335.   if (!partial_symtab_list) {
  1336.     wrap_here ("");
  1337.     printf_filtered ("(no debugging symbols found)...");
  1338.     wrap_here ("");
  1339.   }
  1340.   */
  1341. }
  1342.  
  1343. /* Initialize anything that needs initializing when a completely new
  1344.    symbol file is specified (not just adding some symbols from another
  1345.    file, e.g. a shared library).  */
  1346.  
  1347. static void
  1348. dbx_new_init ()
  1349. {
  1350.   /* Empty the hash table of global syms looking for values.  */
  1351.   bzero (global_sym_chain, sizeof global_sym_chain);
  1352.  
  1353.   free_pendings = 0;
  1354.   file_symbols = 0;
  1355.   global_symbols = 0;
  1356.  
  1357.   /* Don't put these on the cleanup chain; they need to stick around
  1358.      until the next call to dbx_new_init.  *Then* we'll free them. */
  1359.   if (symfile_string_table)
  1360.     {
  1361.       free (symfile_string_table);
  1362.       symfile_string_table = 0;
  1363.       symfile_string_table_size = 0;
  1364.     }
  1365.   free_and_init_header_files ();
  1366. }
  1367.  
  1368.  
  1369. /* dbx_symfile_init ()
  1370.    is the dbx-specific initialization routine for reading symbols.
  1371.    It is passed a struct sym_fns which contains, among other things,
  1372.    the BFD for the file whose symbols are being read, and a slot for a pointer
  1373.    to "private data" which we fill with goodies.
  1374.  
  1375.    We read the string table into malloc'd space and stash a pointer to it.
  1376.  
  1377.    Since BFD doesn't know how to read debug symbols in a format-independent
  1378.    way (and may never do so...), we have to do it ourselves.  We will never
  1379.    be called unless this is an a.out (or very similar) file. 
  1380.    FIXME, there should be a cleaner peephole into the BFD environment here.  */
  1381.  
  1382. static void
  1383. dbx_symfile_init (sf)
  1384.   struct sym_fns *sf;
  1385. {
  1386.   int val;
  1387.   int desc;
  1388.   struct stat statbuf;
  1389.   bfd *sym_bfd = sf->sym_bfd;
  1390.   char *name = bfd_get_filename (sym_bfd);
  1391.   struct dbx_symfile_info *info;
  1392.   unsigned char size_temp[4];
  1393.  
  1394.   /* Allocate struct to keep track of the symfile */
  1395.   sf->sym_private = xmalloc (sizeof (*info));   /* FIXME storage leak */
  1396.   info = (struct dbx_symfile_info *)sf->sym_private;
  1397.  
  1398.   /* FIXME POKING INSIDE BFD DATA STRUCTURES */
  1399.   desc = fileno ((FILE *)(sym_bfd->iostream));    /* Raw file descriptor */
  1400. #define    STRING_TABLE_OFFSET    (sym_bfd->origin + obj_str_filepos (sym_bfd))
  1401. #define    SYMBOL_TABLE_OFFSET    (sym_bfd->origin + obj_sym_filepos (sym_bfd))
  1402.   /* FIXME POKING INSIDE BFD DATA STRUCTURES */
  1403.  
  1404.   info->desc = desc;
  1405.   info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
  1406.   if (!info->text_sect)
  1407.     abort();
  1408.   info->symcount = bfd_get_symcount (sym_bfd);
  1409.  
  1410.   /* Read the string table size and check it for bogosity.  */
  1411.   val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
  1412.   if (val < 0)
  1413.       perror_with_name (name);
  1414.   if (fstat (desc, &statbuf) == -1)
  1415.       perror_with_name (name);
  1416.  
  1417.   val = myread (desc, size_temp, sizeof (long));
  1418.   if (val < 0)
  1419.       perror_with_name (name);
  1420.   info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
  1421.   
  1422.   if (info->stringtab_size >= 0 && info->stringtab_size < statbuf.st_size)
  1423.     {
  1424.       info->stringtab = (char *) xmalloc (info->stringtab_size);
  1425.       /* Caller is responsible for freeing the string table.  No cleanup. */
  1426.     }
  1427.   else
  1428.     info->stringtab = NULL;
  1429.   if (info->stringtab == NULL && info->stringtab_size != 0)
  1430.     error ("ridiculous string table size: %d bytes", info->stringtab_size);
  1431.  
  1432.   /* Now read in the string table in one big gulp.  */
  1433.  
  1434.   val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
  1435.   if (val < 0)
  1436.     perror_with_name (name);
  1437.   val = myread (desc, info->stringtab, info->stringtab_size);
  1438.   if (val < 0)
  1439.     perror_with_name (name);
  1440.  
  1441.   /* Record the position of the symbol table for later use.  */
  1442.  
  1443.   info->symtab_offset = SYMBOL_TABLE_OFFSET;
  1444. }
  1445.  
  1446. /* Buffer for reading the symbol table entries.  */
  1447. static struct internal_nlist symbuf[4096];
  1448. static int symbuf_idx;
  1449. static int symbuf_end;
  1450.  
  1451. /* I/O descriptor for reading the symbol table.  */
  1452. static int symtab_input_desc;
  1453.  
  1454. /* The address in memory of the string table of the object file we are
  1455.    reading (which might not be the "main" object file, but might be a
  1456.    shared library or some other dynamically loaded thing).  This is set
  1457.    by read_dbx_symtab when building psymtabs, and by read_ofile_symtab 
  1458.    when building symtabs, and is used only by next_symbol_text.  */
  1459. static char *stringtab_global;
  1460.  
  1461. /* Refill the symbol table input buffer
  1462.    and set the variables that control fetching entries from it.
  1463.    Reports an error if no data available.
  1464.    This function can read past the end of the symbol table
  1465.    (into the string table) but this does no harm.  */
  1466.  
  1467. static int
  1468. fill_symbuf ()
  1469. {
  1470.   int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf));
  1471.   if (nbytes < 0)
  1472.     perror_with_name ("<symbol file>");
  1473.   else if (nbytes == 0)
  1474.     error ("Premature end of file reading symbol table");
  1475.   symbuf_end = nbytes / symbol_size;
  1476.   symbuf_idx = 0;
  1477.   return 1;
  1478. }
  1479.  
  1480. #define SWAP_SYMBOL(symp) \
  1481.   { \
  1482.     (symp)->n_strx = bfd_h_get_32(symfile_bfd,            \
  1483.                 (unsigned char *)&(symp)->n_strx);    \
  1484.     (symp)->n_desc = bfd_h_get_16 (symfile_bfd,            \
  1485.                 (unsigned char *)&(symp)->n_desc);      \
  1486.     (symp)->n_value = bfd_h_get_32 (symfile_bfd,            \
  1487.                 (unsigned char *)&(symp)->n_value);     \
  1488.   }
  1489.  
  1490. /* Invariant: The symbol pointed to by symbuf_idx is the first one
  1491.    that hasn't been swapped.  Swap the symbol at the same time
  1492.    that symbuf_idx is incremented.  */
  1493.  
  1494. /* dbx allows the text of a symbol name to be continued into the
  1495.    next symbol name!  When such a continuation is encountered
  1496.    (a \ at the end of the text of a name)
  1497.    call this function to get the continuation.  */
  1498.  
  1499. static char *
  1500. next_symbol_text ()
  1501. {
  1502.   if (symbuf_idx == symbuf_end)
  1503.     fill_symbuf ();
  1504.   symnum++;
  1505.   SWAP_SYMBOL(&symbuf[symbuf_idx]);
  1506.   return symbuf[symbuf_idx++].n_strx + stringtab_global;
  1507. }
  1508.  
  1509. /* Initializes storage for all of the partial symbols that will be
  1510.    created by read_dbx_symtab and subsidiaries.  */
  1511.  
  1512. static void
  1513. init_psymbol_list (total_symbols)
  1514.      int total_symbols;
  1515. {
  1516.   /* Free any previously allocated psymbol lists.  */
  1517.   if (global_psymbols.list)
  1518.     free (global_psymbols.list);
  1519.   if (static_psymbols.list)
  1520.     free (static_psymbols.list);
  1521.  
  1522.   /* Current best guess is that there are approximately a twentieth
  1523.      of the total symbols (in a debugging file) are global or static
  1524.      oriented symbols */
  1525.   global_psymbols.size = total_symbols / 10;
  1526.   static_psymbols.size = total_symbols / 10;
  1527.   global_psymbols.next = global_psymbols.list = (struct partial_symbol *)
  1528.     xmalloc (global_psymbols.size * sizeof (struct partial_symbol));
  1529.   static_psymbols.next = static_psymbols.list = (struct partial_symbol *)
  1530.     xmalloc (static_psymbols.size * sizeof (struct partial_symbol));
  1531. }
  1532.  
  1533. /* Initialize the list of bincls to contain none and have some
  1534.    allocated.  */
  1535.  
  1536. static void
  1537. init_bincl_list (number)
  1538.      int number;
  1539. {
  1540.   bincls_allocated = number;
  1541.   next_bincl = bincl_list = (struct header_file_location *)
  1542.       xmalloc (bincls_allocated * sizeof(struct header_file_location));
  1543. }
  1544.  
  1545. /* Add a bincl to the list.  */
  1546.  
  1547. static void
  1548. add_bincl_to_list (pst, name, instance)
  1549.      struct partial_symtab *pst;
  1550.      char *name;
  1551.      int instance;
  1552. {
  1553.   if (next_bincl >= bincl_list + bincls_allocated)
  1554.     {
  1555.       int offset = next_bincl - bincl_list;
  1556.       bincls_allocated *= 2;
  1557.       bincl_list = (struct header_file_location *)
  1558.     xrealloc ((char *)bincl_list,
  1559.           bincls_allocated * sizeof (struct header_file_location));
  1560.       next_bincl = bincl_list + offset;
  1561.     }
  1562.   next_bincl->pst = pst;
  1563.   next_bincl->instance = instance;
  1564.   next_bincl++->name = name;
  1565. }
  1566.  
  1567. /* Given a name, value pair, find the corresponding
  1568.    bincl in the list.  Return the partial symtab associated
  1569.    with that header_file_location.  */
  1570.  
  1571. static struct partial_symtab *
  1572. find_corresponding_bincl_psymtab (name, instance)
  1573.      char *name;
  1574.      int instance;
  1575. {
  1576.   struct header_file_location *bincl;
  1577.  
  1578.   for (bincl = bincl_list; bincl < next_bincl; bincl++)
  1579.     if (bincl->instance == instance
  1580.     && !strcmp (name, bincl->name))
  1581.       return bincl->pst;
  1582.  
  1583.   return (struct partial_symtab *) 0;
  1584. }
  1585.  
  1586. /* Free the storage allocated for the bincl list.  */
  1587.  
  1588. static void
  1589. free_bincl_list ()
  1590. {
  1591.   free (bincl_list);
  1592.   bincls_allocated = 0;
  1593. }
  1594.  
  1595. static struct partial_symtab *start_psymtab ();
  1596. static void end_psymtab();
  1597.  
  1598. #ifdef DEBUG
  1599. /* This is normally a macro defined in read_dbx_symtab, but this
  1600.    is a lot easier to debug.  */
  1601.  
  1602. ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, PLIST, VALUE)
  1603.      char *NAME;
  1604.      int NAMELENGTH;
  1605.      enum namespace NAMESPACE;
  1606.      enum address_class CLASS;
  1607.      struct psymbol_allocation_list *PLIST;
  1608.      unsigned long VALUE;
  1609. {
  1610.   register struct partial_symbol *psym;
  1611.  
  1612. #define LIST *PLIST
  1613.   do {                                        
  1614.     if ((LIST).next >=                    
  1615.     (LIST).list + (LIST).size)            
  1616.       {                                    
  1617.     (LIST).list = (struct partial_symbol *)                
  1618.       xrealloc ((LIST).list,                    
  1619.             ((LIST).size * 2                    
  1620.              * sizeof (struct partial_symbol)));        
  1621.     /* Next assumes we only went one over.  Should be good if    
  1622.        program works correctly */                    
  1623.     (LIST).next =                            
  1624.       (LIST).list + (LIST).size;                
  1625.     (LIST).size *= 2;                
  1626.       }                                    
  1627.     psym = (LIST).next++;                        
  1628. #undef LIST
  1629.  
  1630.     SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack,    
  1631.                          (NAMELENGTH) + 1);    
  1632.     strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH));            
  1633.     SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0';                
  1634.     SYMBOL_NAMESPACE (psym) = (NAMESPACE);                
  1635.     SYMBOL_CLASS (psym) = (CLASS);                
  1636.     SYMBOL_VALUE (psym) = (VALUE);                     
  1637.   } while (0);
  1638. }
  1639.  
  1640. /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
  1641. #define    ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS,  LIST, VALUE) \
  1642.        ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
  1643.  
  1644. #endif /* DEBUG */
  1645.  
  1646. /* Given pointers to an a.out symbol table in core containing dbx
  1647.    style data, setup partial_symtab's describing each source file for
  1648.    which debugging information is available.  NLISTLEN is the number
  1649.    of symbols in the symbol table.  All symbol names are given as
  1650.    offsets relative to STRINGTAB.  STRINGTAB_SIZE is the size of
  1651.    STRINGTAB.  SYMFILE_NAME is the name of the file we are reading from
  1652.    and ADDR is its relocated address (if incremental) or 0 (if not).  */
  1653.  
  1654. static void
  1655. read_dbx_symtab (symfile_name, addr,
  1656.          desc, stringtab, stringtab_size, nlistlen,
  1657.          text_addr, text_size)
  1658.      char *symfile_name;
  1659.      CORE_ADDR addr;
  1660.      int desc;
  1661.      register char *stringtab;
  1662.      register long stringtab_size;
  1663.      register int nlistlen;
  1664.      CORE_ADDR text_addr;
  1665.      int text_size;
  1666. {
  1667.   register struct internal_nlist *bufp;
  1668.   register char *namestring;
  1669.   register struct partial_symbol *psym;
  1670.   int nsl;
  1671.   int past_first_source_file = 0;
  1672.   CORE_ADDR last_o_file_start = 0;
  1673.   struct cleanup *old_chain;
  1674.   char *p;
  1675.  
  1676.   /* End of the text segment of the executable file.  */
  1677.   CORE_ADDR end_of_text_addr;
  1678.  
  1679.   /* Current partial symtab */
  1680.   struct partial_symtab *pst;
  1681.  
  1682.   /* List of current psymtab's include files */
  1683.   char **psymtab_include_list;
  1684.   int includes_allocated;
  1685.   int includes_used;
  1686.  
  1687.   /* Index within current psymtab dependency list */
  1688.   struct partial_symtab **dependency_list;
  1689.   int dependencies_used, dependencies_allocated;
  1690.  
  1691.   stringtab_global = stringtab;
  1692.   
  1693.   pst = (struct partial_symtab *) 0;
  1694.  
  1695.   includes_allocated = 30;
  1696.   includes_used = 0;
  1697.   psymtab_include_list = (char **) alloca (includes_allocated *
  1698.                        sizeof (char *));
  1699.  
  1700.   dependencies_allocated = 30;
  1701.   dependencies_used = 0;
  1702.   dependency_list =
  1703.     (struct partial_symtab **) alloca (dependencies_allocated *
  1704.                        sizeof (struct partial_symtab *));
  1705.  
  1706.   /* FIXME!!  If an error occurs, this blows away the whole symbol table! 
  1707.      It should only blow away the psymtabs created herein.  We could
  1708.      be reading a shared library or a dynloaded file!  */
  1709.   old_chain = make_cleanup (free_all_psymtabs, 0);
  1710.  
  1711.   /* Init bincl list */
  1712.   init_bincl_list (20);
  1713.   make_cleanup (free_bincl_list, 0);
  1714.  
  1715.   last_source_file = 0;
  1716.  
  1717. #ifdef END_OF_TEXT_DEFAULT
  1718.   end_of_text_addr = END_OF_TEXT_DEFAULT;
  1719. #else
  1720.   end_of_text_addr = text_addr + addr + text_size;    /* Relocate */
  1721. #endif
  1722.  
  1723.   symtab_input_desc = desc;    /* This is needed for fill_symbuf below */
  1724.   symbuf_end = symbuf_idx = 0;
  1725.  
  1726.   for (symnum = 0; symnum < nlistlen; symnum++)
  1727.     {
  1728.       /* Get the symbol for this run and pull out some info */
  1729.       QUIT;    /* allow this to be interruptable */
  1730.       if (symbuf_idx == symbuf_end)
  1731.     fill_symbuf ();
  1732.       bufp = &symbuf[symbuf_idx++];
  1733.  
  1734.       /*
  1735.        * Special case to speed up readin.
  1736.        */
  1737.       if (bufp->n_type == (unsigned char)N_SLINE) continue;
  1738.  
  1739.       SWAP_SYMBOL (bufp);
  1740.  
  1741.       /* Ok.  There is a lot of code duplicated in the rest of this
  1742.          switch statement (for efficiency reasons).  Since I don't
  1743.          like duplicating code, I will do my penance here, and
  1744.          describe the code which is duplicated:
  1745.  
  1746.      *) The assignment to namestring.
  1747.      *) The call to strchr.
  1748.      *) The addition of a partial symbol the the two partial
  1749.         symbol lists.  This last is a large section of code, so
  1750.         I've imbedded it in the following macro.
  1751.      */
  1752.       
  1753. /* Set namestring based on bufp.  If the string table index is invalid, 
  1754.    give a fake name, and print a single error message per symbol file read,
  1755.    rather than abort the symbol reading or flood the user with messages.  */
  1756. #define SET_NAMESTRING()\
  1757.   if (bufp->n_strx < 0 || bufp->n_strx >= stringtab_size) {    \
  1758.     complain (&string_table_offset_complaint, symnum);            \
  1759.     namestring = "foo";                            \
  1760.   } else                                \
  1761.     namestring = bufp->n_strx + stringtab
  1762.  
  1763. /* Add a symbol with an integer value to a psymtab. */
  1764. /* This is a macro unless we're debugging.  See above this function. */
  1765. #ifndef DEBUG
  1766. #  define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
  1767.  ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
  1768.                         SYMBOL_VALUE)
  1769. #endif /* DEBUG */
  1770.  
  1771. /* Add a symbol with a CORE_ADDR value to a psymtab. */
  1772. #define    ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
  1773.  ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
  1774.                         SYMBOL_VALUE_ADDRESS)
  1775.  
  1776. /* Add any kind of symbol to a psymtab. */
  1777. #define    ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\
  1778.   do {                                        \
  1779.     if ((LIST).next >=                            \
  1780.     (LIST).list + (LIST).size)                    \
  1781.       {                                    \
  1782.     (LIST).list = (struct partial_symbol *)                \
  1783.       xrealloc ((LIST).list,                    \
  1784.             ((LIST).size * 2                    \
  1785.              * sizeof (struct partial_symbol)));        \
  1786.     /* Next assumes we only went one over.  Should be good if    \
  1787.        program works correctly */                    \
  1788.     (LIST).next =                            \
  1789.       (LIST).list + (LIST).size;                    \
  1790.     (LIST).size *= 2;                        \
  1791.       }                                    \
  1792.     psym = (LIST).next++;                        \
  1793.                                     \
  1794.     SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack,    \
  1795.                          (NAMELENGTH) + 1);    \
  1796.     strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH));            \
  1797.     SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0';                \
  1798.     SYMBOL_NAMESPACE (psym) = (NAMESPACE);                \
  1799.     SYMBOL_CLASS (psym) = (CLASS);                    \
  1800.     VT (psym) = (VALUE);                         \
  1801.   } while (0);
  1802.  
  1803. /* End of macro definitions, now let's handle them symbols!  */
  1804.  
  1805.       switch (bufp->n_type)
  1806.     {
  1807.       /*
  1808.        * Standard, external, non-debugger, symbols
  1809.        */
  1810.  
  1811.     case N_TEXT | N_EXT:
  1812.     case N_NBTEXT | N_EXT:
  1813.     case N_NBDATA | N_EXT:
  1814.     case N_NBBSS | N_EXT:
  1815.     case N_SETV | N_EXT:
  1816.     case N_ABS | N_EXT:
  1817.     case N_DATA | N_EXT:
  1818.     case N_BSS | N_EXT:
  1819.  
  1820.       bufp->n_value += addr;        /* Relocate */
  1821.  
  1822.       SET_NAMESTRING();
  1823.  
  1824.     bss_ext_symbol:
  1825.       record_misc_function (namestring, bufp->n_value,
  1826.                 bufp->n_type); /* Always */
  1827.  
  1828.       continue;
  1829.  
  1830.       /* Standard, local, non-debugger, symbols */
  1831.  
  1832.     case N_NBTEXT:
  1833.  
  1834.       /* We need to be able to deal with both N_FN or N_TEXT,
  1835.          because we have no way of knowing whether the sys-supplied ld
  1836.          or GNU ld was used to make the executable.  Sequents throw
  1837.          in another wrinkle -- they renumbered N_FN.  */
  1838.     case N_FN:
  1839.     case N_FN_SEQ:
  1840.     case N_TEXT:
  1841.       bufp->n_value += addr;        /* Relocate */
  1842.       SET_NAMESTRING();
  1843.       if ((namestring[0] == '-' && namestring[1] == 'l')
  1844.           || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
  1845.           && namestring [nsl - 2] == '.'))
  1846.         {
  1847.           if (entry_point < bufp->n_value
  1848.           && entry_point >= last_o_file_start
  1849.           && addr == 0)        /* FIXME nogood nomore */
  1850.         {
  1851.           startup_file_start = last_o_file_start;
  1852.           startup_file_end = bufp->n_value;
  1853.         }
  1854.           if (past_first_source_file && pst
  1855.           /* The gould NP1 uses low values for .o and -l symbols
  1856.              which are not the address.  */
  1857.           && bufp->n_value > pst->textlow)
  1858.         {
  1859.           end_psymtab (pst, psymtab_include_list, includes_used,
  1860.                    symnum * symbol_size, bufp->n_value,
  1861.                    dependency_list, dependencies_used,
  1862.                    global_psymbols.next, static_psymbols.next);
  1863.           pst = (struct partial_symtab *) 0;
  1864.           includes_used = 0;
  1865.           dependencies_used = 0;
  1866.         }
  1867.           else
  1868.         past_first_source_file = 1;
  1869.           last_o_file_start = bufp->n_value;
  1870.         }
  1871.       continue;
  1872.  
  1873.     case N_DATA:
  1874.       bufp->n_value += addr;        /* Relocate */
  1875.       SET_NAMESTRING ();
  1876.       /* Check for __DYNAMIC, which is used by Sun shared libraries. 
  1877.          Record it even if it's local, not global, so we can find it.
  1878.          Same with virtual function tables, both global and static.  */
  1879.       if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
  1880.           || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
  1881.         {
  1882.           /* Not really a function here, but... */
  1883.           record_misc_function (namestring, bufp->n_value,
  1884.                     bufp->n_type); /* Always */
  1885.       }
  1886.       continue;
  1887.  
  1888.     case N_UNDF | N_EXT:
  1889.       if (bufp->n_value != 0) {
  1890.         /* This is a "Fortran COMMON" symbol.  See if the target
  1891.            environment knows where it has been relocated to.  */
  1892.  
  1893.         CORE_ADDR reladdr;
  1894.  
  1895.         SET_NAMESTRING();
  1896.         if (target_lookup_symbol (namestring, &reladdr)) {
  1897.           continue;        /* Error in lookup; ignore symbol for now.  */
  1898.         }
  1899.         bufp->n_type ^= (N_BSS^N_UNDF);    /* Define it as a bss-symbol */
  1900.         bufp->n_value = reladdr;
  1901.         goto bss_ext_symbol;
  1902.       }
  1903.       continue;    /* Just undefined, not COMMON */
  1904.  
  1905.         /* Lots of symbol types we can just ignore.  */
  1906.  
  1907.     case N_UNDF:
  1908.     case N_ABS:
  1909.     case N_BSS:
  1910.     case N_NBDATA:
  1911.     case N_NBBSS:
  1912.       continue;
  1913.  
  1914.       /* Keep going . . .*/
  1915.  
  1916.       /*
  1917.        * Special symbol types for GNU
  1918.        */
  1919.     case N_INDR:
  1920.     case N_INDR | N_EXT:
  1921.     case N_SETA:
  1922.     case N_SETA | N_EXT:
  1923.     case N_SETT:
  1924.     case N_SETT | N_EXT:
  1925.     case N_SETD:
  1926.     case N_SETD | N_EXT:
  1927.     case N_SETB:
  1928.     case N_SETB | N_EXT:
  1929.     case N_SETV:
  1930.       continue;
  1931.  
  1932.       /*
  1933.        * Debugger symbols
  1934.        */
  1935.  
  1936.     case N_SO: {
  1937.       unsigned long valu = bufp->n_value;
  1938.       /* Symbol number of the first symbol of this file (i.e. the N_SO
  1939.          if there is just one, or the first if we have a pair).  */
  1940.       int first_symnum = symnum;
  1941.       
  1942.       /* End the current partial symtab and start a new one */
  1943.  
  1944.       SET_NAMESTRING();
  1945.  
  1946.       /* Peek at the next symbol.  If it is also an N_SO, the
  1947.          first one just indicates the directory.  */
  1948.       if (symbuf_idx == symbuf_end)
  1949.         fill_symbuf ();
  1950.       bufp = &symbuf[symbuf_idx];
  1951.       /* n_type is only a char, so swapping swapping is irrelevant.  */
  1952.       if (bufp->n_type == (unsigned char)N_SO)
  1953.         {
  1954.           SWAP_SYMBOL (bufp);
  1955.           SET_NAMESTRING ();
  1956.           valu = bufp->n_value;
  1957.           symbuf_idx++;
  1958.           symnum++;
  1959.         }
  1960.       valu += addr;        /* Relocate */
  1961.  
  1962.       if (pst && past_first_source_file)
  1963.         {
  1964.           end_psymtab (pst, psymtab_include_list, includes_used,
  1965.                first_symnum * symbol_size, valu,
  1966.                dependency_list, dependencies_used,
  1967.                global_psymbols.next, static_psymbols.next);
  1968.           pst = (struct partial_symtab *) 0;
  1969.           includes_used = 0;
  1970.           dependencies_used = 0;
  1971.         }
  1972.       else
  1973.         past_first_source_file = 1;
  1974.  
  1975.       pst = start_psymtab (symfile_name, addr,
  1976.                    namestring, valu,
  1977.                    first_symnum * symbol_size,
  1978.                    global_psymbols.next, static_psymbols.next);
  1979.       continue;
  1980.     }
  1981.  
  1982.     case N_BINCL:
  1983.       /* Add this bincl to the bincl_list for future EXCLs.  No
  1984.          need to save the string; it'll be around until
  1985.          read_dbx_symtab function returns */
  1986.  
  1987.       SET_NAMESTRING();
  1988.  
  1989.       add_bincl_to_list (pst, namestring, bufp->n_value);
  1990.  
  1991.       /* Mark down an include file in the current psymtab */
  1992.  
  1993.       psymtab_include_list[includes_used++] = namestring;
  1994.       if (includes_used >= includes_allocated)
  1995.         {
  1996.           char **orig = psymtab_include_list;
  1997.  
  1998.           psymtab_include_list = (char **)
  1999.         alloca ((includes_allocated *= 2) *
  2000.             sizeof (char *));
  2001.           bcopy (orig, psymtab_include_list,
  2002.              includes_used * sizeof (char *));
  2003.         }
  2004.  
  2005.       continue;
  2006.  
  2007.     case N_SOL:
  2008.       /* Mark down an include file in the current psymtab */
  2009.  
  2010.       SET_NAMESTRING();
  2011.  
  2012.       /* In C++, one may expect the same filename to come round many
  2013.          times, when code is coming alternately from the main file
  2014.          and from inline functions in other files. So I check to see
  2015.          if this is a file we've seen before -- either the main
  2016.          source file, or a previously included file.
  2017.  
  2018.          This seems to be a lot of time to be spending on N_SOL, but
  2019.          things like "break c-exp.y:435" need to work (I
  2020.          suppose the psymtab_include_list could be hashed or put
  2021.          in a binary tree, if profiling shows this is a major hog).  */
  2022.       if (pst && !strcmp (namestring, pst->filename))
  2023.         continue;
  2024.       {
  2025.         register int i;
  2026.         for (i = 0; i < includes_used; i++)
  2027.           if (!strcmp (namestring, psymtab_include_list[i]))
  2028.         {
  2029.           i = -1; 
  2030.           break;
  2031.         }
  2032.         if (i == -1)
  2033.           continue;
  2034.       }
  2035.  
  2036.       psymtab_include_list[includes_used++] = namestring;
  2037.       if (includes_used >= includes_allocated)
  2038.         {
  2039.           char **orig = psymtab_include_list;
  2040.  
  2041.           psymtab_include_list = (char **)
  2042.         alloca ((includes_allocated *= 2) *
  2043.             sizeof (char *));
  2044.           bcopy (orig, psymtab_include_list,
  2045.              includes_used * sizeof (char *));
  2046.         }
  2047.       continue;
  2048.  
  2049.     case N_LSYM:        /* Typedef or automatic variable. */
  2050.     case N_STSYM:        /* Data seg var -- static  */
  2051.     case N_LCSYM:        /* BSS      "  */
  2052.     case N_NBSTS:           /* Gould nobase.  */
  2053.     case N_NBLCS:           /* symbols.  */
  2054.  
  2055.       SET_NAMESTRING();
  2056.  
  2057.       p = (char *) strchr (namestring, ':');
  2058.  
  2059.       /* Skip if there is no :.  */
  2060.       if (!p) continue;
  2061.  
  2062.       switch (p[1])
  2063.         {
  2064.         case 'T':
  2065.           ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
  2066.                    STRUCT_NAMESPACE, LOC_TYPEDEF,
  2067.                    static_psymbols, bufp->n_value);
  2068.           if (p[2] == 't')
  2069.         {
  2070.           /* Also a typedef with the same name.  */
  2071.           ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
  2072.                        VAR_NAMESPACE, LOC_TYPEDEF,
  2073.                        static_psymbols, bufp->n_value);
  2074.           p += 1;
  2075.         }
  2076.           goto check_enum;
  2077.         case 't':
  2078.           ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
  2079.                    VAR_NAMESPACE, LOC_TYPEDEF,
  2080.                    static_psymbols, bufp->n_value);
  2081.         check_enum:
  2082.           /* If this is an enumerated type, we need to
  2083.          add all the enum constants to the partial symbol
  2084.          table.  This does not cover enums without names, e.g.
  2085.          "enum {a, b} c;" in C, but fortunately those are
  2086.          rare.  There is no way for GDB to find those from the
  2087.          enum type without spending too much time on it.  Thus
  2088.          to solve this problem, the compiler needs to put out separate
  2089.          constant symbols ('c' N_LSYMS) for enum constants in
  2090.          enums without names, or put out a dummy type.  */
  2091.  
  2092.           /* We are looking for something of the form
  2093.          <name> ":" ("t" | "T") [<number> "="] "e"
  2094.          {<constant> ":" <value> ","} ";".  */
  2095.  
  2096.           /* Skip over the colon and the 't' or 'T'.  */
  2097.           p += 2;
  2098.           /* This type may be given a number.  Skip over it.  */
  2099.           while ((*p >= '0' && *p <= '9')
  2100.              || *p == '=')
  2101.         p++;
  2102.  
  2103.           if (*p++ == 'e')
  2104.         {
  2105.           /* We have found an enumerated type.  */
  2106.           /* According to comments in read_enum_type
  2107.              a comma could end it instead of a semicolon.
  2108.              I don't know where that happens.
  2109.              Accept either.  */
  2110.           while (*p && *p != ';' && *p != ',')
  2111.             {
  2112.               char *q;
  2113.  
  2114.               /* Check for and handle cretinous dbx symbol name
  2115.              continuation!  */
  2116.               if (*p == '\\')
  2117.             p = next_symbol_text ();
  2118.  
  2119.               /* Point to the character after the name
  2120.              of the enum constant.  */
  2121.               for (q = p; *q && *q != ':'; q++)
  2122.             ;
  2123.               /* Note that the value doesn't matter for
  2124.              enum constants in psymtabs, just in symtabs.  */
  2125.               ADD_PSYMBOL_TO_LIST (p, q - p,
  2126.                        VAR_NAMESPACE, LOC_CONST,
  2127.                        static_psymbols, 0);
  2128.               /* Point past the name.  */
  2129.               p = q;
  2130.               /* Skip over the value.  */
  2131.               while (*p && *p != ',')
  2132.             p++;
  2133.               /* Advance past the comma.  */
  2134.               if (*p)
  2135.             p++;
  2136.             }
  2137.         }
  2138.  
  2139.           continue;
  2140.         case 'c':
  2141.           /* Constant, e.g. from "const" in Pascal.  */
  2142.           ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
  2143.                    VAR_NAMESPACE, LOC_CONST,
  2144.                    static_psymbols, bufp->n_value);
  2145.           continue;
  2146.         default:
  2147.           /* Skip if the thing following the : is
  2148.              not a letter (which indicates declaration of a local
  2149.              variable, which we aren't interested in).  */
  2150.           continue;
  2151.         }
  2152.  
  2153.     case N_FUN:
  2154.     case N_GSYM:        /* Global (extern) variable; can be
  2155.                    data or bss (sigh).  */
  2156.  
  2157.     /* Following may probably be ignored; I'll leave them here
  2158.        for now (until I do Pascal and Modula 2 extensions).  */
  2159.  
  2160.     case N_PC:        /* I may or may not need this; I
  2161.                    suspect not.  */
  2162.     case N_M2C:        /* I suspect that I can ignore this here. */
  2163.     case N_SCOPE:        /* Same.   */
  2164.  
  2165.       SET_NAMESTRING();
  2166.  
  2167.       p = (char *) strchr (namestring, ':');
  2168.       if (!p)
  2169.         continue;        /* Not a debugging symbol.   */
  2170.  
  2171.  
  2172.  
  2173.       /* Main processing section for debugging symbols which
  2174.          the initial read through the symbol tables needs to worry
  2175.          about.  If we reach this point, the symbol which we are
  2176.          considering is definitely one we are interested in.
  2177.          p must also contain the (valid) index into the namestring
  2178.          which indicates the debugging type symbol.  */
  2179.  
  2180.       switch (p[1])
  2181.         {
  2182.         case 'c':
  2183.           ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
  2184.                    VAR_NAMESPACE, LOC_CONST,
  2185.                    static_psymbols, bufp->n_value);
  2186.           continue;
  2187.         case 'S':
  2188.           bufp->n_value += addr;        /* Relocate */
  2189.           ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
  2190.                    VAR_NAMESPACE, LOC_STATIC,
  2191.                    static_psymbols, bufp->n_value);
  2192.           continue;
  2193.         case 'G':
  2194.           bufp->n_value += addr;        /* Relocate */
  2195.           /* The addresses in these entries are reported to be
  2196.          wrong.  See the code that reads 'G's for symtabs. */
  2197.           ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
  2198.                    VAR_NAMESPACE, LOC_STATIC,
  2199.                    global_psymbols, bufp->n_value);
  2200.           continue;
  2201.  
  2202.         case 't':
  2203.           ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
  2204.                    VAR_NAMESPACE, LOC_TYPEDEF,
  2205.                    static_psymbols, bufp->n_value);
  2206.           continue;
  2207.  
  2208.         case 'f':
  2209.           ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
  2210.                    VAR_NAMESPACE, LOC_BLOCK,
  2211.                    static_psymbols, bufp->n_value);
  2212.           continue;
  2213.  
  2214.           /* Global functions were ignored here, but now they
  2215.              are put into the global psymtab like one would expect.
  2216.          They're also in the misc fn vector... 
  2217.          FIXME, why did it used to ignore these?  That broke
  2218.          "i fun" on these functions.  */
  2219.         case 'F':
  2220.           ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
  2221.                    VAR_NAMESPACE, LOC_BLOCK,
  2222.                    global_psymbols, bufp->n_value);
  2223.           continue;
  2224.  
  2225.           /* Two things show up here (hopefully); static symbols of
  2226.          local scope (static used inside braces) or extensions
  2227.          of structure symbols.  We can ignore both.  */
  2228.         case 'V':
  2229.         case '(':
  2230.         case '0':
  2231.         case '1':
  2232.         case '2':
  2233.         case '3':
  2234.         case '4':
  2235.         case '5':
  2236.         case '6':
  2237.         case '7':
  2238.         case '8':
  2239.         case '9':
  2240.           continue;
  2241.  
  2242.         default:
  2243.           /* Unexpected symbol.  Ignore it; perhaps it is an extension
  2244.          that we don't know about.
  2245.  
  2246.          Someone says sun cc puts out symbols like
  2247.          /foo/baz/maclib::/usr/local/bin/maclib,
  2248.          which would get here with a symbol type of ':'.  */
  2249.           continue;
  2250.         }
  2251.  
  2252.     case N_EXCL:
  2253.  
  2254.       SET_NAMESTRING();
  2255.  
  2256.       /* Find the corresponding bincl and mark that psymtab on the
  2257.          psymtab dependency list */
  2258.       {
  2259.         struct partial_symtab *needed_pst =
  2260.           find_corresponding_bincl_psymtab (namestring, bufp->n_value);
  2261.  
  2262.         /* If this include file was defined earlier in this file,
  2263.            leave it alone.  */
  2264.         if (needed_pst == pst) continue;
  2265.  
  2266.         if (needed_pst)
  2267.           {
  2268.         int i;
  2269.         int found = 0;
  2270.  
  2271.         for (i = 0; i < dependencies_used; i++)
  2272.           if (dependency_list[i] == needed_pst)
  2273.             {
  2274.               found = 1;
  2275.               break;
  2276.             }
  2277.  
  2278.         /* If it's already in the list, skip the rest.  */
  2279.         if (found) continue;
  2280.  
  2281.         dependency_list[dependencies_used++] = needed_pst;
  2282.         if (dependencies_used >= dependencies_allocated)
  2283.           {
  2284.             struct partial_symtab **orig = dependency_list;
  2285.             dependency_list =
  2286.               (struct partial_symtab **)
  2287.             alloca ((dependencies_allocated *= 2)
  2288.                 * sizeof (struct partial_symtab *));
  2289.             bcopy (orig, dependency_list,
  2290.                (dependencies_used
  2291.                 * sizeof (struct partial_symtab *)));
  2292. #ifdef DEBUG_INFO
  2293.             fprintf (stderr, "Had to reallocate dependency list.\n");
  2294.             fprintf (stderr, "New dependencies allocated: %d\n",
  2295.                  dependencies_allocated);
  2296. #endif
  2297.           }
  2298.           }
  2299.         else
  2300.           error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
  2301.              symnum);
  2302.       }
  2303.       continue;
  2304.  
  2305.     case N_EINCL:
  2306.     case N_DSLINE:
  2307.     case N_BSLINE:
  2308.     case N_SSYM:        /* Claim: Structure or union element.
  2309.                    Hopefully, I can ignore this.  */
  2310.     case N_ENTRY:        /* Alternate entry point; can ignore. */
  2311.     case N_MAIN:        /* Can definitely ignore this.   */
  2312.     case N_CATCH:        /* These are GNU C++ extensions */
  2313.     case N_EHDECL:        /* that can safely be ignored here. */
  2314.     case N_LENG:
  2315.     case N_BCOMM:
  2316.     case N_ECOMM:
  2317.     case N_ECOML:
  2318.     case N_FNAME:
  2319.     case N_SLINE:
  2320.     case N_RSYM:
  2321.     case N_PSYM:
  2322.     case N_LBRAC:
  2323.     case N_RBRAC:
  2324.     case N_NSYMS:        /* Ultrix 4.0: symbol count */
  2325.     case N_DEFD:        /* GNU Modula-2 */
  2326.       /* These symbols aren't interesting; don't worry about them */
  2327.  
  2328.       continue;
  2329.  
  2330.     default:
  2331.       /* If we haven't found it yet, ignore it.  It's probably some
  2332.          new type we don't know about yet.  */
  2333.       complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type));
  2334.       continue;
  2335.     }
  2336.     }
  2337.  
  2338.   /* If there's stuff to be cleaned up, clean it up.  */
  2339.   if (nlistlen > 0                /* We have some syms */
  2340.       && entry_point < bufp->n_value
  2341.       && entry_point >= last_o_file_start)
  2342.     {
  2343.       startup_file_start = last_o_file_start;
  2344.       startup_file_end = bufp->n_value;
  2345.     }
  2346.  
  2347.   if (pst)
  2348.     {
  2349.       end_psymtab (pst, psymtab_include_list, includes_used,
  2350.            symnum * symbol_size, end_of_text_addr,
  2351.            dependency_list, dependencies_used,
  2352.            global_psymbols.next, static_psymbols.next);
  2353.       includes_used = 0;
  2354.       dependencies_used = 0;
  2355.       pst = (struct partial_symtab *) 0;
  2356.     }
  2357.  
  2358.   free_bincl_list ();
  2359.   discard_cleanups (old_chain);
  2360. }
  2361.  
  2362. /*
  2363.  * Allocate and partially fill a partial symtab.  It will be
  2364.  * completely filled at the end of the symbol list.
  2365.  
  2366.  SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
  2367.  is the address relative to which its symbols are (incremental) or 0
  2368.  (normal).  */
  2369. static struct partial_symtab *
  2370. start_psymtab (symfile_name, addr,
  2371.            filename, textlow, ldsymoff, global_syms, static_syms)
  2372.      char *symfile_name;
  2373.      CORE_ADDR addr;
  2374.      char *filename;
  2375.      CORE_ADDR textlow;
  2376.      int ldsymoff;
  2377.      struct partial_symbol *global_syms;
  2378.      struct partial_symbol *static_syms;
  2379. {
  2380.   struct partial_symtab *result =
  2381.     (struct partial_symtab *) obstack_alloc (psymbol_obstack,
  2382.                          sizeof (struct partial_symtab));
  2383.  
  2384.   result->addr = addr;
  2385.  
  2386.   result->symfile_name =
  2387.     (char *) obstack_alloc (psymbol_obstack,
  2388.                 strlen (symfile_name) + 1);
  2389.   strcpy (result->symfile_name, symfile_name);
  2390.   
  2391.   result->filename =
  2392.     (char *) obstack_alloc (psymbol_obstack,
  2393.                 strlen (filename) + 1);
  2394.   strcpy (result->filename, filename);
  2395.  
  2396.   result->textlow = textlow;
  2397.   result->ldsymoff = ldsymoff;
  2398.  
  2399.   result->readin = 0;
  2400.   result->symtab = 0;
  2401.   result->read_symtab = dbx_psymtab_to_symtab;
  2402.  
  2403.   result->globals_offset = global_syms - global_psymbols.list;
  2404.   result->statics_offset = static_syms - static_psymbols.list;
  2405.  
  2406.   result->n_global_syms = 0;
  2407.   result->n_static_syms = 0;
  2408.  
  2409.  
  2410.   return result;
  2411. }
  2412.  
  2413. static int
  2414. compare_psymbols (s1, s2)
  2415.      register struct partial_symbol *s1, *s2;
  2416. {
  2417.   register char
  2418.     *st1 = SYMBOL_NAME (s1),
  2419.     *st2 = SYMBOL_NAME (s2);
  2420.  
  2421.   if (st1[0] - st2[0])
  2422.     return st1[0] - st2[0];
  2423.   if (st1[1] - st2[1])
  2424.     return st1[1] - st2[1];
  2425.   return strcmp (st1 + 1, st2 + 1);
  2426. }
  2427.  
  2428.  
  2429. /* Close off the current usage of a partial_symbol table entry.  This
  2430.    involves setting the correct number of includes (with a realloc),
  2431.    setting the high text mark, setting the symbol length in the
  2432.    executable, and setting the length of the global and static lists
  2433.    of psymbols.
  2434.  
  2435.    The global symbols and static symbols are then seperately sorted.
  2436.  
  2437.    Then the partial symtab is put on the global list.
  2438.    *** List variables and peculiarities of same. ***
  2439.    */
  2440. static void
  2441. end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
  2442.          capping_text, dependency_list, number_dependencies,
  2443.          capping_global, capping_static)
  2444.      struct partial_symtab *pst;
  2445.      char **include_list;
  2446.      int num_includes;
  2447.      int capping_symbol_offset;
  2448.      CORE_ADDR capping_text;
  2449.      struct partial_symtab **dependency_list;
  2450.      int number_dependencies;
  2451.      struct partial_symbol *capping_global, *capping_static;
  2452. {
  2453.   int i;
  2454.  
  2455.   pst->ldsymlen = capping_symbol_offset - pst->ldsymoff;
  2456.   pst->texthigh = capping_text;
  2457.  
  2458.   pst->n_global_syms =
  2459.     capping_global - (global_psymbols.list + pst->globals_offset);
  2460.   pst->n_static_syms =
  2461.     capping_static - (static_psymbols.list + pst->statics_offset);
  2462.  
  2463.   pst->number_of_dependencies = number_dependencies;
  2464.   if (number_dependencies)
  2465.     {
  2466.       pst->dependencies = (struct partial_symtab **)
  2467.     obstack_alloc (psymbol_obstack,
  2468.                number_dependencies * sizeof (struct partial_symtab *));
  2469.       bcopy (dependency_list, pst->dependencies,
  2470.          number_dependencies * sizeof (struct partial_symtab *));
  2471.     }
  2472.   else
  2473.     pst->dependencies = 0;
  2474.  
  2475.   for (i = 0; i < num_includes; i++)
  2476.     {
  2477.       /* Eventually, put this on obstack */
  2478.       struct partial_symtab *subpst =
  2479.     (struct partial_symtab *)
  2480.       obstack_alloc (psymbol_obstack,
  2481.              sizeof (struct partial_symtab));
  2482.  
  2483.       subpst->filename =
  2484.     (char *) obstack_alloc (psymbol_obstack,
  2485.                 strlen (include_list[i]) + 1);
  2486.       strcpy (subpst->filename, include_list[i]);
  2487.  
  2488.       subpst->symfile_name = pst->symfile_name;
  2489.       subpst->addr = pst->addr;
  2490.       subpst->ldsymoff =
  2491.     subpst->ldsymlen =
  2492.       subpst->textlow =
  2493.         subpst->texthigh = 0;
  2494.  
  2495.       /* We could save slight bits of space by only making one of these,
  2496.      shared by the entire set of include files.  FIXME-someday.  */
  2497.       subpst->dependencies = (struct partial_symtab **)
  2498.     obstack_alloc (psymbol_obstack,
  2499.                sizeof (struct partial_symtab *));
  2500.       subpst->dependencies[0] = pst;
  2501.       subpst->number_of_dependencies = 1;
  2502.  
  2503.       subpst->globals_offset =
  2504.     subpst->n_global_syms =
  2505.       subpst->statics_offset =
  2506.         subpst->n_static_syms = 0;
  2507.  
  2508.       subpst->readin = 0;
  2509.       subpst->symtab = 0;
  2510.       subpst->read_symtab = dbx_psymtab_to_symtab;
  2511.  
  2512.       subpst->next = partial_symtab_list;
  2513.       partial_symtab_list = subpst;
  2514.     }
  2515.  
  2516.   /* Sort the global list; don't sort the static list */
  2517.   qsort (global_psymbols.list + pst->globals_offset, pst->n_global_syms,
  2518.      sizeof (struct partial_symbol), compare_psymbols);
  2519.  
  2520.   /* If there is already a psymtab or symtab for a file of this name, remove it.
  2521.      (If there is a symtab, more drastic things also happen.)
  2522.      This happens in VxWorks.  */
  2523.   free_named_symtabs (pst->filename);
  2524.  
  2525.   /* Put the psymtab on the psymtab list */
  2526.   pst->next = partial_symtab_list;
  2527.   partial_symtab_list = pst;
  2528. }
  2529.  
  2530. static void
  2531. psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset)
  2532.      struct partial_symtab *pst;
  2533.      int desc;
  2534.      char *stringtab;
  2535.      int stringtab_size;
  2536.      int sym_offset;
  2537. {
  2538.   struct cleanup *old_chain;
  2539.   int i;
  2540.   
  2541.   if (!pst)
  2542.     return;
  2543.  
  2544.   if (pst->readin)
  2545.     {
  2546.       fprintf (stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
  2547.            pst->filename);
  2548.       return;
  2549.     }
  2550.  
  2551.   /* Read in all partial symtabs on which this one is dependent */
  2552.   for (i = 0; i < pst->number_of_dependencies; i++)
  2553.     if (!pst->dependencies[i]->readin)
  2554.       {
  2555.     /* Inform about additional files that need to be read in.  */
  2556.     if (info_verbose)
  2557.       {
  2558.         fputs_filtered (" ", stdout);
  2559.         wrap_here ("");
  2560.         fputs_filtered ("and ", stdout);
  2561.         wrap_here ("");
  2562.         printf_filtered ("%s...", pst->dependencies[i]->filename);
  2563.         wrap_here ("");        /* Flush output */
  2564.         fflush (stdout);
  2565.       }
  2566.     psymtab_to_symtab_1 (pst->dependencies[i], desc,
  2567.                  stringtab, stringtab_size, sym_offset);
  2568.       }
  2569.  
  2570.   if (pst->ldsymlen)        /* Otherwise it's a dummy */
  2571.     {
  2572.       /* Init stuff necessary for reading in symbols */
  2573.       free_pendings = 0;
  2574.       pending_blocks = 0;
  2575.       file_symbols = 0;
  2576.       global_symbols = 0;
  2577.       old_chain = make_cleanup (really_free_pendings, 0);
  2578.  
  2579.       /* Read in this files symbols */
  2580.       lseek (desc, sym_offset, L_SET);
  2581.       pst->symtab =
  2582.     read_ofile_symtab (desc, stringtab, stringtab_size,
  2583.                pst->ldsymoff,
  2584.                pst->ldsymlen, pst->textlow,
  2585.                pst->texthigh - pst->textlow, pst->addr);
  2586.       sort_symtab_syms (pst->symtab);
  2587.  
  2588.       do_cleanups (old_chain);
  2589.     }
  2590.  
  2591.   pst->readin = 1;
  2592. }
  2593.  
  2594. /*
  2595.  * Read in all of the symbols for a given psymtab for real.
  2596.  * Be verbose about it if the user wants that.
  2597.  */
  2598. static void
  2599. dbx_psymtab_to_symtab (pst)
  2600.      struct partial_symtab *pst;
  2601. {
  2602.   int desc;
  2603.   char *stringtab;
  2604.   int stsize, val;
  2605.   struct stat statbuf;
  2606.   struct cleanup *old_chain;
  2607.   bfd *sym_bfd;
  2608.   long st_temp;
  2609.  
  2610.   if (!pst)
  2611.     return;
  2612.  
  2613.   if (pst->readin)
  2614.     {
  2615.       fprintf (stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
  2616.            pst->filename);
  2617.       return;
  2618.     }
  2619.  
  2620.   if (pst->ldsymlen || pst->number_of_dependencies)
  2621.     {
  2622.       /* Print the message now, before reading the string table,
  2623.      to avoid disconcerting pauses.  */
  2624.       if (info_verbose)
  2625.     {
  2626.       printf_filtered ("Reading in symbols for %s...", pst->filename);
  2627.       fflush (stdout);
  2628.     }
  2629.  
  2630.       /* Open symbol file and read in string table.  Symbol_file_command
  2631.      guarantees that the symbol file name will be absolute, so there is
  2632.      no need for openp.  */
  2633.       desc = open(pst->symfile_name, O_RDONLY, 0);
  2634.  
  2635.       if (desc < 0)
  2636.     perror_with_name (pst->symfile_name);
  2637.  
  2638.       sym_bfd = bfd_fdopenr (pst->symfile_name, NULL, desc);
  2639.       if (!sym_bfd)
  2640.     {
  2641.       (void)close (desc);
  2642.       error ("Could not open `%s' to read symbols: %s",
  2643.          pst->symfile_name, bfd_errmsg (bfd_error));
  2644.     }
  2645.       old_chain = make_cleanup (bfd_close, sym_bfd);
  2646.       if (!bfd_check_format (sym_bfd, bfd_object))
  2647.       error ("\"%s\": can't read symbols: %s.",
  2648.          pst->symfile_name, bfd_errmsg (bfd_error));
  2649.  
  2650.       /* We keep the string table for symfile resident in memory, but
  2651.      not the string table for any other symbol files.  */
  2652.       if ((symfile == 0) || 0 != strcmp(pst->symfile_name, symfile))
  2653.     {
  2654.       /* Read in the string table */
  2655.  
  2656.       /* FIXME, this uses internal BFD variables.  See above in
  2657.          dbx_symbol_file_open where the macro is defined!  */
  2658.       lseek (desc, STRING_TABLE_OFFSET, L_SET);
  2659.  
  2660.       val = myread (desc, &st_temp, sizeof st_temp);
  2661.       if (val < 0)
  2662.           perror_with_name (pst->symfile_name);
  2663.       stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
  2664.       if (fstat (desc, &statbuf) < 0)
  2665.         perror_with_name (pst->symfile_name);
  2666.       
  2667.       if (stsize >= 0 && stsize < statbuf.st_size)
  2668.         {
  2669. #ifdef BROKEN_LARGE_ALLOCA
  2670.           stringtab = (char *) xmalloc (stsize);
  2671.           make_cleanup (free, stringtab);
  2672. #else
  2673.           stringtab = (char *) alloca (stsize);
  2674. #endif
  2675.         }
  2676.       else
  2677.         stringtab = NULL;
  2678.       if (stringtab == NULL && stsize != 0)
  2679.         error ("ridiculous string table size: %d bytes", stsize);
  2680.  
  2681.       /* FIXME, this uses internal BFD variables.  See above in
  2682.          dbx_symbol_file_open where the macro is defined!  */
  2683.       val = lseek (desc, STRING_TABLE_OFFSET, L_SET);
  2684.       if (val < 0)
  2685.         perror_with_name (pst->symfile_name);
  2686.       val = myread (desc, stringtab, stsize);
  2687.       if (val < 0)
  2688.         perror_with_name (pst->symfile_name);
  2689.     }
  2690.       else
  2691.     {
  2692.       stringtab = symfile_string_table;
  2693.       stsize = symfile_string_table_size;
  2694.     }
  2695.  
  2696.       symfile_bfd = sym_bfd;        /* Kludge for SWAP_SYMBOL */
  2697.       /* FIXME POKING INSIDE BFD DATA STRUCTURES */
  2698.       symbol_size = obj_symbol_entry_size (sym_bfd);
  2699.  
  2700.       /* FIXME, this uses internal BFD variables.  See above in
  2701.      dbx_symbol_file_open where the macro is defined!  */
  2702.       psymtab_to_symtab_1 (pst, desc, stringtab, stsize,
  2703.                SYMBOL_TABLE_OFFSET);
  2704.  
  2705.       /* Match with global symbols.  This only needs to be done once,
  2706.          after all of the symtabs and dependencies have been read in.   */
  2707.       scan_file_globals ();
  2708.  
  2709.       do_cleanups (old_chain);
  2710.  
  2711.       /* Finish up the debug error message.  */
  2712.       if (info_verbose)
  2713.     printf_filtered ("done.\n");
  2714.     }
  2715. }
  2716.  
  2717. /*
  2718.  * Scan through all of the global symbols defined in the object file,
  2719.  * assigning values to the debugging symbols that need to be assigned
  2720.  * to.  Get these symbols from the misc function list.
  2721.  */
  2722. static void
  2723. scan_file_globals ()
  2724. {
  2725.   int hash;
  2726.   int mf;
  2727.  
  2728.   for (mf = 0; mf < misc_function_count; mf++)
  2729.     {
  2730.       char *namestring = misc_function_vector[mf].name;
  2731.       struct symbol *sym, *prev;
  2732.  
  2733.       QUIT;
  2734.  
  2735.       prev = (struct symbol *) 0;
  2736.  
  2737.       /* Get the hash index and check all the symbols
  2738.      under that hash index. */
  2739.  
  2740.       hash = hashname (namestring);
  2741.  
  2742.       for (sym = global_sym_chain[hash]; sym;)
  2743.     {
  2744.       if (*namestring == SYMBOL_NAME (sym)[0]
  2745.           && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1))
  2746.         {
  2747.           /* Splice this symbol out of the hash chain and
  2748.          assign the value we have to it. */
  2749.           if (prev)
  2750.         SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
  2751.           else
  2752.         global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
  2753.           
  2754.           /* Check to see whether we need to fix up a common block.  */
  2755.           /* Note: this code might be executed several times for
  2756.          the same symbol if there are multiple references.  */
  2757.           if (SYMBOL_CLASS (sym) == LOC_BLOCK)
  2758.         fix_common_block (sym, misc_function_vector[mf].address);
  2759.           else
  2760.         SYMBOL_VALUE_ADDRESS (sym) = misc_function_vector[mf].address;
  2761.           
  2762.           if (prev)
  2763.         sym = SYMBOL_VALUE_CHAIN (prev);
  2764.           else
  2765.         sym = global_sym_chain[hash];
  2766.         }
  2767.       else
  2768.         {
  2769.           prev = sym;
  2770.           sym = SYMBOL_VALUE_CHAIN (sym);
  2771.         }
  2772.     }
  2773.     }
  2774. }
  2775.  
  2776. /* Process a pair of symbols.  Currently they must both be N_SO's.  */
  2777. /* ARGSUSED */
  2778. static void
  2779. process_symbol_pair (type1, desc1, value1, name1,
  2780.              type2, desc2, value2, name2)
  2781.      int type1;
  2782.      int desc1;
  2783.      CORE_ADDR value1;
  2784.      char *name1;
  2785.      int type2;
  2786.      int desc2;
  2787.      CORE_ADDR value2;
  2788.      char *name2;
  2789. {
  2790.   /* No need to check PCC_SOL_BROKEN, on the assumption that such
  2791.      broken PCC's don't put out N_SO pairs.  */
  2792.   if (last_source_file)
  2793.     (void)end_symtab (value2);
  2794.   start_symtab (name2, name1, value2);
  2795. }
  2796.  
  2797. /*
  2798.  * Read in a defined section of a specific object file's symbols.
  2799.  *
  2800.  * DESC is the file descriptor for the file, positioned at the
  2801.  * beginning of the symtab
  2802.  * STRINGTAB is a pointer to the files string
  2803.  * table, already read in
  2804.  * SYM_OFFSET is the offset within the file of
  2805.  * the beginning of the symbols we want to read, NUM_SUMBOLS is the
  2806.  * number of symbols to read
  2807.  * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
  2808.  * TEXT_SIZE is the size of the text segment read in.
  2809.  * OFFSET is a relocation offset which gets added to each symbol
  2810.  */
  2811.  
  2812. static struct symtab *
  2813. read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
  2814.            sym_size, text_offset, text_size, offset)
  2815.      int desc;
  2816.      register char *stringtab;
  2817.      unsigned int stringtab_size;
  2818.      int sym_offset;
  2819.      int sym_size;
  2820.      CORE_ADDR text_offset;
  2821.      int text_size;
  2822.      int offset;
  2823. {
  2824.   register char *namestring;
  2825.   struct internal_nlist *bufp;
  2826.   unsigned char type;
  2827.   unsigned max_symnum;
  2828.   subfile_stack = 0;
  2829.  
  2830.   stringtab_global = stringtab;
  2831.   last_source_file = 0;
  2832.  
  2833.   symtab_input_desc = desc;
  2834.   symbuf_end = symbuf_idx = 0;
  2835.  
  2836.   /* It is necessary to actually read one symbol *before* the start
  2837.      of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
  2838.      occurs before the N_SO symbol.
  2839.  
  2840.      Detecting this in read_dbx_symtab
  2841.      would slow down initial readin, so we look for it here instead.  */
  2842.   if (sym_offset >= (int)symbol_size)
  2843.     {
  2844.       lseek (desc, sym_offset - symbol_size, L_INCR);
  2845.       fill_symbuf ();
  2846.       bufp = &symbuf[symbuf_idx++];
  2847.       SWAP_SYMBOL (bufp);
  2848.  
  2849.       SET_NAMESTRING ();
  2850.  
  2851.       processing_gcc_compilation =
  2852.     (bufp->n_type == N_TEXT
  2853.      && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL));
  2854.       /* FIXME!!!  Check for gcc2_compiled... */
  2855.     }
  2856.   else
  2857.     {
  2858.       /* The N_SO starting this symtab is the first symbol, so we
  2859.      better not check the symbol before it.  I'm not this can
  2860.      happen, but it doesn't hurt to check for it.  */
  2861.       lseek(desc, sym_offset, L_INCR);
  2862.       processing_gcc_compilation = 0;
  2863.     }
  2864.  
  2865.   if (symbuf_idx == symbuf_end)
  2866.     fill_symbuf();
  2867.   bufp = &symbuf[symbuf_idx];
  2868.   if (bufp->n_type != (unsigned char)N_SO)
  2869.     error("First symbol in segment of executable not a source symbol");
  2870.  
  2871.   max_symnum = sym_size / symbol_size;
  2872.  
  2873.   for (symnum = 0;
  2874.        symnum < max_symnum;
  2875.        symnum++)
  2876.     {
  2877.       QUIT;            /* Allow this to be interruptable */
  2878.       if (symbuf_idx == symbuf_end)
  2879.     fill_symbuf();
  2880.       bufp = &symbuf[symbuf_idx++];
  2881.       SWAP_SYMBOL (bufp);
  2882.  
  2883.       type = bufp->n_type & N_TYPE;
  2884.       if (type == (unsigned char)N_CATCH)
  2885.     {
  2886.       /* N_CATCH is not fixed up by the linker, and unfortunately,
  2887.          there's no other place to put it in the .stab map.  */
  2888.       bufp->n_value += text_offset + offset;
  2889.     }
  2890.       else if (type == N_TEXT || type == N_DATA || type == N_BSS)
  2891.     bufp->n_value += offset;
  2892.  
  2893.       type = bufp->n_type;
  2894.       SET_NAMESTRING ();
  2895.  
  2896.       if (type & N_STAB)
  2897.     {
  2898.       short bufp_n_desc = bufp->n_desc;
  2899.       unsigned long valu = bufp->n_value;
  2900.  
  2901.       /* Check for a pair of N_SO symbols.  */
  2902.       if (type == (unsigned char)N_SO)
  2903.         {
  2904.           if (symbuf_idx == symbuf_end)
  2905.         fill_symbuf ();
  2906.           bufp = &symbuf[symbuf_idx];
  2907.           if (bufp->n_type == (unsigned char)N_SO)
  2908.         {
  2909.           char *namestring1 = namestring;
  2910.  
  2911.           SWAP_SYMBOL (bufp);
  2912.           bufp->n_value += offset;        /* Relocate */
  2913.           symbuf_idx++;
  2914.           symnum++;
  2915.           SET_NAMESTRING ();
  2916.  
  2917.           process_symbol_pair (N_SO, bufp_n_desc, valu, namestring1,
  2918.                        N_SO, bufp->n_desc, bufp->n_value,
  2919.                        namestring);
  2920.         }
  2921.           else
  2922.         process_one_symbol(type, bufp_n_desc, valu, namestring);
  2923.         }
  2924.       else
  2925.         process_one_symbol (type, bufp_n_desc, valu, namestring);
  2926.     }
  2927.       /* We skip checking for a new .o or -l file; that should never
  2928.          happen in this routine. */
  2929.       else if (type == N_TEXT
  2930.            && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL))
  2931.     /* I don't think this code will ever be executed, because
  2932.        the GCC_COMPILED_FLAG_SYMBOL usually is right before
  2933.        the N_SO symbol which starts this source file.
  2934.        However, there is no reason not to accept
  2935.        the GCC_COMPILED_FLAG_SYMBOL anywhere.  */
  2936.     processing_gcc_compilation = 1;
  2937.       else if (type & N_EXT || type == (unsigned char)N_TEXT
  2938.            || type == (unsigned char)N_NBTEXT
  2939.            ) {
  2940.       /* Global symbol: see if we came across a dbx defintion for
  2941.          a corresponding symbol.  If so, store the value.  Remove
  2942.          syms from the chain when their values are stored, but
  2943.          search the whole chain, as there may be several syms from
  2944.          different files with the same name. */
  2945.       /* This is probably not true.  Since the files will be read
  2946.          in one at a time, each reference to a global symbol will
  2947.          be satisfied in each file as it appears. So we skip this
  2948.          section. */
  2949.       ;
  2950.         }
  2951.     }
  2952.  
  2953.   return end_symtab (text_offset + text_size);
  2954. }
  2955.  
  2956. static int
  2957. hashname (name)
  2958.      char *name;
  2959. {
  2960.   register char *p = name;
  2961.   register int total = p[0];
  2962.   register int c;
  2963.  
  2964.   c = p[1];
  2965.   total += c << 2;
  2966.   if (c)
  2967.     {
  2968.       c = p[2];
  2969.       total += c << 4;
  2970.       if (c)
  2971.     total += p[3] << 6;
  2972.     }
  2973.  
  2974.   /* Ensure result is positive.  */
  2975.   if (total < 0) total += (1000 << 6);
  2976.   return total % HASHSIZE;
  2977. }
  2978.  
  2979.  
  2980. static void
  2981. process_one_symbol (type, desc, valu, name)
  2982.      int type, desc;
  2983.      CORE_ADDR valu;
  2984.      char *name;
  2985. {
  2986. #ifndef SUN_FIXED_LBRAC_BUG
  2987.   /* This records the last pc address we've seen.  We depend on their being
  2988.      an SLINE or FUN or SO before the first LBRAC, since the variable does
  2989.      not get reset in between reads of different symbol files.  */
  2990.   static CORE_ADDR last_pc_address;
  2991. #endif
  2992.   register struct context_stack *new;
  2993.   char *colon_pos;
  2994.  
  2995.   /* Something is wrong if we see real data before
  2996.      seeing a source file name.  */
  2997.  
  2998.   if (last_source_file == 0 && type != (unsigned char)N_SO)
  2999.     {
  3000.       /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
  3001.      where that code is defined.  */
  3002.       if (IGNORE_SYMBOL (type))
  3003.     return;
  3004.  
  3005.       /* FIXME, this should not be an error, since it precludes extending
  3006.          the symbol table information in this way...  */
  3007.       error ("Invalid symbol data: does not start by identifying a source file.");
  3008.     }
  3009.  
  3010.   switch (type)
  3011.     {
  3012.     case N_FUN:
  3013.     case N_FNAME:
  3014.       /* Either of these types of symbols indicates the start of
  3015.      a new function.  We must process its "name" normally for dbx,
  3016.      but also record the start of a new lexical context, and possibly
  3017.      also the end of the lexical context for the previous function.  */
  3018.       /* This is not always true.  This type of symbol may indicate a
  3019.          text segment variable.  */
  3020.  
  3021. #ifndef SUN_FIXED_LBRAC_BUG
  3022.       last_pc_address = valu;    /* Save for SunOS bug circumcision */
  3023. #endif
  3024.  
  3025.       colon_pos = strchr (name, ':');
  3026.       if (!colon_pos++
  3027.       || (*colon_pos != 'f' && *colon_pos != 'F'))
  3028.     {
  3029.       define_symbol (valu, name, desc, type);
  3030.       break;
  3031.     }
  3032.  
  3033.       within_function = 1;
  3034.       if (context_stack_depth > 0)
  3035.     {
  3036.       new = &context_stack[--context_stack_depth];
  3037.       /* Make a block for the local symbols within.  */
  3038.       finish_block (new->name, &local_symbols, new->old_blocks,
  3039.             new->start_addr, valu);
  3040.     }
  3041.       /* Stack must be empty now.  */
  3042.       if (context_stack_depth != 0)
  3043.     error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
  3044.            symnum);
  3045.  
  3046.       new = &context_stack[context_stack_depth++];
  3047.       new->old_blocks = pending_blocks;
  3048.       new->start_addr = valu;
  3049.       new->name = define_symbol (valu, name, desc, type);
  3050.       local_symbols = 0;
  3051.       break;
  3052.  
  3053.     case N_CATCH:
  3054.       /* Record the address at which this catch takes place.  */
  3055.       define_symbol (valu, name, desc, type);
  3056.       break;
  3057.  
  3058.     case N_EHDECL:
  3059.       /* Don't know what to do with these yet.  */
  3060.       error ("action uncertain for eh extensions");
  3061.       break;
  3062.  
  3063.     case N_LBRAC:
  3064.       /* This "symbol" just indicates the start of an inner lexical
  3065.      context within a function.  */
  3066.  
  3067. #if !defined (BLOCK_ADDRESS_ABSOLUTE)
  3068.       /* On most machines, the block addresses are relative to the
  3069.      N_SO, the linker did not relocate them (sigh).  */
  3070.       valu += last_source_start_addr;
  3071. #endif
  3072.  
  3073. #ifndef SUN_FIXED_LBRAC_BUG
  3074.       if (valu < last_pc_address) {
  3075.     /* Patch current LBRAC pc value to match last handy pc value */
  3076.      complain (&lbrac_complaint, 0);
  3077.     valu = last_pc_address;
  3078.       }
  3079. #endif
  3080.       if (context_stack_depth == context_stack_size)
  3081.     {
  3082.       context_stack_size *= 2;
  3083.       context_stack = (struct context_stack *)
  3084.         xrealloc (context_stack,
  3085.               (context_stack_size
  3086.                * sizeof (struct context_stack)));
  3087.     }
  3088.  
  3089.       new = &context_stack[context_stack_depth++];
  3090.       new->depth = desc;
  3091.       new->locals = local_symbols;
  3092.       new->old_blocks = pending_blocks;
  3093.       new->start_addr = valu;
  3094.       new->name = 0;
  3095.       local_symbols = 0;
  3096.       break;
  3097.  
  3098.     case N_RBRAC:
  3099.       /* This "symbol" just indicates the end of an inner lexical
  3100.      context that was started with N_LBRAC.  */
  3101.  
  3102. #if !defined (BLOCK_ADDRESS_ABSOLUTE)
  3103.       /* On most machines, the block addresses are relative to the
  3104.      N_SO, the linker did not relocate them (sigh).  */
  3105.       valu += last_source_start_addr;
  3106. #endif
  3107.  
  3108.       new = &context_stack[--context_stack_depth];
  3109.       if (desc != new->depth)
  3110.     error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum);
  3111.  
  3112.       /* Some compilers put the variable decls inside of an
  3113.          LBRAC/RBRAC block.  This macro should be nonzero if this
  3114.      is true.  DESC is N_DESC from the N_RBRAC symbol.
  3115.      GCC_P is true if we've detected the GCC_COMPILED_SYMBOL.  */
  3116. #if !defined (VARIABLES_INSIDE_BLOCK)
  3117. #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
  3118. #endif
  3119.  
  3120.       /* Can only use new->locals as local symbols here if we're in
  3121.          gcc or on a machine that puts them before the lbrack.  */
  3122.       if (!VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
  3123.     local_symbols = new->locals;
  3124.  
  3125.       /* If this is not the outermost LBRAC...RBRAC pair in the
  3126.      function, its local symbols preceded it, and are the ones
  3127.      just recovered from the context stack.  Defined the block for them.
  3128.  
  3129.      If this is the outermost LBRAC...RBRAC pair, there is no
  3130.      need to do anything; leave the symbols that preceded it
  3131.      to be attached to the function's own block.  However, if
  3132.      it is so, we need to indicate that we just moved outside
  3133.      of the function.  */
  3134.       if (local_symbols
  3135.       && (context_stack_depth
  3136.           > !VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation)))
  3137.     {
  3138.       /* FIXME Muzzle a compiler bug that makes end < start.  */
  3139.       if (new->start_addr > valu)
  3140.         {
  3141.           complain(&lbrac_rbrac_complaint, 0);
  3142.           new->start_addr = valu;
  3143.         }
  3144.       /* Make a block for the local symbols within.  */
  3145.       finish_block (0, &local_symbols, new->old_blocks,
  3146.             new->start_addr, valu);
  3147.     }
  3148.       else
  3149.     {
  3150.       within_function = 0;
  3151.     }
  3152.       if (VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
  3153.     /* Now pop locals of block just finished.  */
  3154.     local_symbols = new->locals;
  3155.       break;
  3156.  
  3157.     case N_FN:
  3158.     case N_FN_SEQ:
  3159.       /* This kind of symbol indicates the start of an object file.  */
  3160.       break;
  3161.  
  3162.     case N_SO:
  3163.       /* This type of symbol indicates the start of data
  3164.      for one source file.
  3165.      Finish the symbol table of the previous source file
  3166.      (if any) and start accumulating a new symbol table.  */
  3167. #ifndef SUN_FIXED_LBRAC_BUG
  3168.       last_pc_address = valu;    /* Save for SunOS bug circumcision */
  3169. #endif
  3170.   
  3171. #ifdef PCC_SOL_BROKEN
  3172.       /* pcc bug, occasionally puts out SO for SOL.  */
  3173.       if (context_stack_depth > 0)
  3174.     {
  3175.       start_subfile (name, NULL);
  3176.       break;
  3177.     }
  3178. #endif
  3179.       if (last_source_file)
  3180.     (void)end_symtab (valu);
  3181.       start_symtab (name, NULL, valu);
  3182.       break;
  3183.  
  3184.     case N_SOL:
  3185.       /* This type of symbol indicates the start of data for
  3186.      a sub-source-file, one whose contents were copied or
  3187.      included in the compilation of the main source file
  3188.      (whose name was given in the N_SO symbol.)  */
  3189.       start_subfile (name, NULL);
  3190.       break;
  3191.  
  3192.     case N_BINCL:
  3193.       push_subfile ();
  3194.       add_new_header_file (name, valu);
  3195.       start_subfile (name, NULL);
  3196.       break;
  3197.  
  3198.     case N_EINCL:
  3199.       start_subfile (pop_subfile (), NULL);
  3200.       break;
  3201.  
  3202.     case N_EXCL:
  3203.       add_old_header_file (name, valu);
  3204.       break;
  3205.  
  3206.     case N_SLINE:
  3207.       /* This type of "symbol" really just records
  3208.      one line-number -- core-address correspondence.
  3209.      Enter it in the line list for this symbol table.  */
  3210. #ifndef SUN_FIXED_LBRAC_BUG
  3211.       last_pc_address = valu;    /* Save for SunOS bug circumcision */
  3212. #endif
  3213.       record_line (desc, valu);
  3214.       break;
  3215.  
  3216.     case N_BCOMM:
  3217.       if (common_block)
  3218.     error ("Invalid symbol data: common within common at symtab pos %d",
  3219.            symnum);
  3220.       common_block = local_symbols;
  3221.       common_block_i = local_symbols ? local_symbols->nsyms : 0;
  3222.       break;
  3223.  
  3224.     case N_ECOMM:
  3225.       /* Symbols declared since the BCOMM are to have the common block
  3226.      start address added in when we know it.  common_block points to
  3227.      the first symbol after the BCOMM in the local_symbols list;
  3228.      copy the list and hang it off the symbol for the common block name
  3229.      for later fixup.  */
  3230.       {
  3231.     int i;
  3232.     struct symbol *sym =
  3233.       (struct symbol *) xmalloc (sizeof (struct symbol));
  3234.     bzero (sym, sizeof *sym);
  3235.     SYMBOL_NAME (sym) = savestring (name, strlen (name));
  3236.     SYMBOL_CLASS (sym) = LOC_BLOCK;
  3237.     SYMBOL_NAMESPACE (sym) = (enum namespace)((long)
  3238.       copy_pending (local_symbols, common_block_i, common_block));
  3239.     i = hashname (SYMBOL_NAME (sym));
  3240.     SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
  3241.     global_sym_chain[i] = sym;
  3242.     common_block = 0;
  3243.     break;
  3244.       }
  3245.  
  3246.     case N_ECOML:
  3247.     case N_LENG:
  3248.     case N_DEFD:        /* GNU Modula-2 symbol */
  3249.       break;
  3250.  
  3251.     default:
  3252.       if (name)
  3253.     define_symbol (valu, name, desc, type);
  3254.     }
  3255. }
  3256.  
  3257. /* Read a number by which a type is referred to in dbx data,
  3258.    or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
  3259.    Just a single number N is equivalent to (0,N).
  3260.    Return the two numbers by storing them in the vector TYPENUMS.
  3261.    TYPENUMS will then be used as an argument to dbx_lookup_type.  */
  3262.  
  3263. static void
  3264. read_type_number (pp, typenums)
  3265.      register char **pp;
  3266.      register int *typenums;
  3267. {
  3268.   if (**pp == '(')
  3269.     {
  3270.       (*pp)++;
  3271.       typenums[0] = read_number (pp, ',');
  3272.       typenums[1] = read_number (pp, ')');
  3273.     }
  3274.   else
  3275.     {
  3276.       typenums[0] = 0;
  3277.       typenums[1] = read_number (pp, 0);
  3278.     }
  3279. }
  3280.  
  3281. /* To handle GNU C++ typename abbreviation, we need to be able to
  3282.    fill in a type's name as soon as space for that type is allocated.
  3283.    `type_synonym_name' is the name of the type being allocated.
  3284.    It is cleared as soon as it is used (lest all allocated types
  3285.    get this name).  */
  3286. static char *type_synonym_name;
  3287.  
  3288. /* ARGSUSED */
  3289. static struct symbol *
  3290. define_symbol (valu, string, desc, type)
  3291.      unsigned int valu;
  3292.      char *string;
  3293.      int desc;
  3294.      int type;
  3295. {
  3296.   register struct symbol *sym;
  3297.   char *p = (char *) strchr (string, ':');
  3298.   int deftype;
  3299.   int synonym = 0;
  3300.   register int i;
  3301.  
  3302.   /* Ignore syms with empty names.  */
  3303.   if (string[0] == 0)
  3304.     return 0;
  3305.  
  3306.   /* Ignore old-style symbols from cc -go  */
  3307.   if (p == 0)
  3308.     return 0;
  3309.  
  3310.   sym = (struct symbol *)obstack_alloc (symbol_obstack, sizeof (struct symbol));
  3311.  
  3312.   if (processing_gcc_compilation) {
  3313.     /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
  3314.        number of bytes occupied by a type or object, which we ignore.  */
  3315.     SYMBOL_LINE(sym) = desc;
  3316.   } else {
  3317.     SYMBOL_LINE(sym) = 0;            /* unknown */
  3318.   }
  3319.  
  3320.   if (string[0] == CPLUS_MARKER)
  3321.     {
  3322.       /* Special GNU C++ names.  */
  3323.       switch (string[1])
  3324.     {
  3325.     case 't':
  3326.       SYMBOL_NAME (sym) = "this";
  3327.       break;
  3328.     case 'v': /* $vtbl_ptr_type */
  3329.       /* Was: SYMBOL_NAME (sym) = "vptr"; */
  3330.       goto normal;
  3331.     case 'e':
  3332.       SYMBOL_NAME (sym) = "eh_throw";
  3333.       break;
  3334.  
  3335.     case '_':
  3336.       /* This was an anonymous type that was never fixed up.  */
  3337.       goto normal;
  3338.  
  3339.     default:
  3340.       abort ();
  3341.     }
  3342.     }
  3343.   else
  3344.     {
  3345.     normal:
  3346.       SYMBOL_NAME (sym)
  3347.     = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
  3348.       /* Open-coded bcopy--saves function call time.  */
  3349.       {
  3350.     register char *p1 = string;
  3351.     register char *p2 = SYMBOL_NAME (sym);
  3352.     while (p1 != p)
  3353.       *p2++ = *p1++;
  3354.     *p2++ = '\0';
  3355.       }
  3356.     }
  3357.   p++;
  3358.   /* Determine the type of name being defined.  */
  3359.   /* The Acorn RISC machine's compiler can put out locals that don't
  3360.      start with "234=" or "(3,4)=", so assume anything other than the
  3361.      deftypes we know how to handle is a local.  */
  3362.   /* (Peter Watkins @ Computervision)
  3363.      Handle Sun-style local fortran array types 'ar...' . 
  3364.      (gnu@cygnus.com) -- this strchr() handles them properly?
  3365.      (tiemann@cygnus.com) -- 'C' is for catch.  */
  3366.   if (!strchr ("cfFGpPrStTvVXC", *p))
  3367.     deftype = 'l';
  3368.   else
  3369.     deftype = *p++;
  3370.  
  3371.   /* c is a special case, not followed by a type-number.
  3372.      SYMBOL:c=iVALUE for an integer constant symbol.
  3373.      SYMBOL:c=rVALUE for a floating constant symbol.
  3374.      SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
  3375.         e.g. "b:c=e6,0" for "const b = blob1"
  3376.     (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
  3377.   if (deftype == 'c')
  3378.     {
  3379.       if (*p++ != '=')
  3380.     error ("Invalid symbol data at symtab pos %d.", symnum);
  3381.       switch (*p++)
  3382.     {
  3383.     case 'r':
  3384.       {
  3385.         double d = atof (p);
  3386.         char *dbl_valu;
  3387.  
  3388.         SYMBOL_TYPE (sym) = builtin_type_double;
  3389.         dbl_valu =
  3390.           (char *) obstack_alloc (symbol_obstack, sizeof (double));
  3391.         bcopy (&d, dbl_valu, sizeof (double));
  3392.         SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
  3393.         SYMBOL_VALUE_BYTES (sym) = dbl_valu;
  3394.         SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
  3395.       }
  3396.       break;
  3397.     case 'i':
  3398.       {
  3399.         SYMBOL_TYPE (sym) = builtin_type_int;
  3400.         SYMBOL_VALUE (sym) = atoi (p);
  3401.         SYMBOL_CLASS (sym) = LOC_CONST;
  3402.       }
  3403.       break;
  3404.     case 'e':
  3405.       /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
  3406.          e.g. "b:c=e6,0" for "const b = blob1"
  3407.          (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
  3408.       {
  3409.         int typenums[2];
  3410.         
  3411.         read_type_number (&p, typenums);
  3412.         if (*p++ != ',')
  3413.           error ("Invalid symbol data: no comma in enum const symbol");
  3414.         
  3415.         SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
  3416.         SYMBOL_VALUE (sym) = atoi (p);
  3417.         SYMBOL_CLASS (sym) = LOC_CONST;
  3418.       }
  3419.       break;
  3420.     default:
  3421.       error ("Invalid symbol data at symtab pos %d.", symnum);
  3422.     }
  3423.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3424.       add_symbol_to_list (sym, &file_symbols);
  3425.       return sym;
  3426.     }
  3427.  
  3428.   /* Now usually comes a number that says which data type,
  3429.      and possibly more stuff to define the type
  3430.      (all of which is handled by read_type)  */
  3431.  
  3432.   if (deftype == 'p' && *p == 'F')
  3433.     /* pF is a two-letter code that means a function parameter in Fortran.
  3434.        The type-number specifies the type of the return value.
  3435.        Translate it into a pointer-to-function type.  */
  3436.     {
  3437.       p++;
  3438.       SYMBOL_TYPE (sym)
  3439.     = lookup_pointer_type (lookup_function_type (read_type (&p)));
  3440.     }
  3441.   else
  3442.     {
  3443.       struct type *type_read;
  3444.       synonym = *p == 't';
  3445.  
  3446.       if (synonym)
  3447.     {
  3448.       p += 1;
  3449.       type_synonym_name = obsavestring (SYMBOL_NAME (sym),
  3450.                         strlen (SYMBOL_NAME (sym)));
  3451.     }
  3452.  
  3453.       type_read = read_type (&p);
  3454.  
  3455.       if ((deftype == 'F' || deftype == 'f')
  3456.       && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
  3457.       {
  3458. #if 0
  3459. /* This code doesn't work -- it needs to realloc and can't.  */
  3460.     struct type *new = (struct type *)
  3461.           obstack_alloc (symbol_obstack, sizeof (struct type));
  3462.  
  3463.     /* Generate a template for the type of this function.  The 
  3464.        types of the arguments will be added as we read the symbol 
  3465.        table. */
  3466.     *new = *lookup_function_type (type_read);
  3467.     SYMBOL_TYPE(sym) = new;
  3468.     in_function_type = new;
  3469. #else
  3470.     SYMBOL_TYPE (sym) = lookup_function_type (type_read);
  3471. #endif
  3472.       }
  3473.       else
  3474.     SYMBOL_TYPE (sym) = type_read;
  3475.     }
  3476.  
  3477.   switch (deftype)
  3478.     {
  3479.     case 'C':
  3480.       /* The name of a caught exception.  */
  3481.       SYMBOL_CLASS (sym) = LOC_LABEL;
  3482.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3483.       SYMBOL_VALUE_ADDRESS (sym) = valu;
  3484.       add_symbol_to_list (sym, &local_symbols);
  3485.       break;
  3486.  
  3487.     case 'f':
  3488.       SYMBOL_CLASS (sym) = LOC_BLOCK;
  3489.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3490.       add_symbol_to_list (sym, &file_symbols);
  3491.       break;
  3492.  
  3493.     case 'F':
  3494.       SYMBOL_CLASS (sym) = LOC_BLOCK;
  3495.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3496.       add_symbol_to_list (sym, &global_symbols);
  3497.       break;
  3498.  
  3499.     case 'G':
  3500.       /* For a class G (global) symbol, it appears that the
  3501.      value is not correct.  It is necessary to search for the
  3502.      corresponding linker definition to find the value.
  3503.      These definitions appear at the end of the namelist.  */
  3504.       i = hashname (SYMBOL_NAME (sym));
  3505.       SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
  3506.       global_sym_chain[i] = sym;
  3507.       SYMBOL_CLASS (sym) = LOC_STATIC;
  3508.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3509.       add_symbol_to_list (sym, &global_symbols);
  3510.       break;
  3511.  
  3512.       /* This case is faked by a conditional above,
  3513.      when there is no code letter in the dbx data.
  3514.      Dbx data never actually contains 'l'.  */
  3515.     case 'l':
  3516.       SYMBOL_CLASS (sym) = LOC_LOCAL;
  3517.       SYMBOL_VALUE (sym) = valu;
  3518.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3519.       add_symbol_to_list (sym, &local_symbols);
  3520.       break;
  3521.  
  3522.     case 'p':
  3523.       /* Normally this is a parameter, a LOC_ARG.  On the i960, it
  3524.      can also be a LOC_LOCAL_ARG depending on symbol type.  */
  3525. #ifndef DBX_PARM_SYMBOL_CLASS
  3526. #define    DBX_PARM_SYMBOL_CLASS(type)    LOC_ARG
  3527. #endif
  3528.       SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
  3529.       SYMBOL_VALUE (sym) = valu;
  3530.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3531. #if 0
  3532.       /* This doesn't work yet.  */
  3533.       add_param_to_type (&in_function_type, sym);
  3534. #endif
  3535.       add_symbol_to_list (sym, &local_symbols);
  3536.  
  3537.       /* If it's gcc-compiled, if it says `short', believe it.  */
  3538.       if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
  3539.     break;
  3540.  
  3541. #if defined(BELIEVE_PCC_PROMOTION_TYPE)
  3542.       /* This macro is defined on machines (e.g. sparc) where
  3543.      we should believe the type of a PCC 'short' argument,
  3544.      but shouldn't believe the address (the address is
  3545.      the address of the corresponding int).  Note that
  3546.      this is only different from the BELIEVE_PCC_PROMOTION
  3547.      case on big-endian machines.
  3548.  
  3549.      My guess is that this correction, as opposed to changing
  3550.      the parameter to an 'int' (as done below, for PCC
  3551.      on most machines), is the right thing to do
  3552.      on all machines, but I don't want to risk breaking
  3553.      something that already works.  On most PCC machines,
  3554.      the sparc problem doesn't come up because the calling
  3555.      function has to zero the top bytes (not knowing whether
  3556.      the called function wants an int or a short), so there
  3557.      is no practical difference between an int and a short
  3558.      (except perhaps what happens when the GDB user types
  3559.      "print short_arg = 0x10000;"). 
  3560.  
  3561.      Hacked for SunOS 4.1 by gnu@cygnus.com.  In 4.1, the compiler
  3562.      actually produces the correct address (we don't need to fix it
  3563.      up).  I made this code adapt so that it will offset the symbol
  3564.      if it was pointing at an int-aligned location and not
  3565.      otherwise.  This way you can use the same gdb for 4.0.x and
  3566.      4.1 systems.  */
  3567.  
  3568.       if (0 == SYMBOL_VALUE (sym) % sizeof (int))
  3569.     {
  3570.       if (SYMBOL_TYPE (sym) == builtin_type_char
  3571.           || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
  3572.         SYMBOL_VALUE (sym) += 3;
  3573.       else if (SYMBOL_TYPE (sym) == builtin_type_short
  3574.           || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
  3575.         SYMBOL_VALUE (sym) += 2;
  3576.     }
  3577.       break;
  3578.  
  3579. #else /* no BELIEVE_PCC_PROMOTION_TYPE.  */
  3580.  
  3581.       /* If PCC says a parameter is a short or a char,
  3582.      it is really an int.  */
  3583.       if (SYMBOL_TYPE (sym) == builtin_type_char
  3584.       || SYMBOL_TYPE (sym) == builtin_type_short)
  3585.     SYMBOL_TYPE (sym) = builtin_type_int;
  3586.       else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
  3587.            || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
  3588.     SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
  3589.       break;
  3590.  
  3591. #endif /* no BELIEVE_PCC_PROMOTION_TYPE.  */
  3592.  
  3593.     case 'P':
  3594.       SYMBOL_CLASS (sym) = LOC_REGPARM;
  3595.       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
  3596.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3597.       add_symbol_to_list (sym, &local_symbols);
  3598.       break;
  3599.  
  3600.     case 'r':
  3601.       SYMBOL_CLASS (sym) = LOC_REGISTER;
  3602.       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
  3603.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3604.       add_symbol_to_list (sym, &local_symbols);
  3605.       break;
  3606.  
  3607.     case 'S':
  3608.       /* Static symbol at top level of file */
  3609.       SYMBOL_CLASS (sym) = LOC_STATIC;
  3610.       SYMBOL_VALUE_ADDRESS (sym) = valu;
  3611.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3612.       add_symbol_to_list (sym, &file_symbols);
  3613.       break;
  3614.  
  3615.     case 't':
  3616.       SYMBOL_CLASS (sym) = LOC_TYPEDEF;
  3617.       SYMBOL_VALUE (sym) = valu;
  3618.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3619.       if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
  3620.       && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
  3621.     TYPE_NAME (SYMBOL_TYPE (sym)) =
  3622.       obsavestring (SYMBOL_NAME (sym),
  3623.             strlen (SYMBOL_NAME (sym)));
  3624.        /* C++ vagaries: we may have a type which is derived from
  3625.       a base type which did not have its name defined when the
  3626.       derived class was output.  We fill in the derived class's
  3627.       base part member's name here in that case.  */
  3628.        else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
  3629.          || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
  3630.         && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
  3631.      {
  3632.        int j;
  3633.        for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
  3634.          if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
  3635.            TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
  3636.          type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
  3637.      }
  3638.  
  3639.       add_symbol_to_list (sym, &file_symbols);
  3640.       break;
  3641.  
  3642.     case 'T':
  3643.       SYMBOL_CLASS (sym) = LOC_TYPEDEF;
  3644.       SYMBOL_VALUE (sym) = valu;
  3645.       SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
  3646.       if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
  3647.       && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
  3648.     TYPE_NAME (SYMBOL_TYPE (sym))
  3649.       = obconcat ("",
  3650.               (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
  3651.                ? "enum "
  3652.                : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
  3653.               ? "struct " : "union ")),
  3654.               SYMBOL_NAME (sym));
  3655.       add_symbol_to_list (sym, &file_symbols);
  3656.  
  3657.       if (synonym)
  3658.     {
  3659.       register struct symbol *typedef_sym
  3660.         = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
  3661.       SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
  3662.       SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
  3663.  
  3664.       SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
  3665.       SYMBOL_VALUE (typedef_sym) = valu;
  3666.       SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
  3667.       add_symbol_to_list (typedef_sym, &file_symbols);
  3668.     }
  3669.       break;
  3670.  
  3671.     case 'V':
  3672.       /* Static symbol of local scope */
  3673.       SYMBOL_CLASS (sym) = LOC_STATIC;
  3674.       SYMBOL_VALUE_ADDRESS (sym) = valu;
  3675.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3676.       add_symbol_to_list (sym, &local_symbols);
  3677.       break;
  3678.  
  3679.     case 'v':
  3680.       /* Reference parameter */
  3681.       SYMBOL_CLASS (sym) = LOC_REF_ARG;
  3682.       SYMBOL_VALUE (sym) = valu;
  3683.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3684.       add_symbol_to_list (sym, &local_symbols);
  3685.       break;
  3686.  
  3687.     case 'X':
  3688.       /* This is used by Sun FORTRAN for "function result value".
  3689.      Sun claims ("dbx and dbxtool interfaces", 2nd ed)
  3690.      that Pascal uses it too, but when I tried it Pascal used
  3691.      "x:3" (local symbol) instead.  */
  3692.       SYMBOL_CLASS (sym) = LOC_LOCAL;
  3693.       SYMBOL_VALUE (sym) = valu;
  3694.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  3695.       add_symbol_to_list (sym, &local_symbols);
  3696.       break;
  3697.  
  3698.     default:
  3699.       error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
  3700.     }
  3701.   return sym;
  3702. }
  3703.  
  3704. /* What about types defined as forward references inside of a small lexical
  3705.    scope?  */
  3706. /* Add a type to the list of undefined types to be checked through
  3707.    once this file has been read in.  */
  3708. static void
  3709. add_undefined_type (type)
  3710.      struct type *type;
  3711. {
  3712.   if (undef_types_length == undef_types_allocated)
  3713.     {
  3714.       undef_types_allocated *= 2;
  3715.       undef_types = (struct type **)
  3716.     xrealloc (undef_types,
  3717.           undef_types_allocated * sizeof (struct type *));
  3718.     }
  3719.   undef_types[undef_types_length++] = type;
  3720. }
  3721.  
  3722. /* Add here something to go through each undefined type, see if it's
  3723.    still undefined, and do a full lookup if so.  */
  3724. static void
  3725. cleanup_undefined_types ()
  3726. {
  3727.   struct type **type;
  3728.  
  3729.   for (type = undef_types; type < undef_types + undef_types_length; type++)
  3730.     {
  3731.       /* Reasonable test to see if it's been defined since.  */
  3732.       if (TYPE_NFIELDS (*type) == 0)
  3733.     {
  3734.       struct pending *ppt;
  3735.       int i;
  3736.       /* Name of the type, without "struct" or "union" */
  3737.       char *typename = TYPE_NAME (*type);
  3738.  
  3739.       if (!strncmp (typename, "struct ", 7))
  3740.         typename += 7;
  3741.       if (!strncmp (typename, "union ", 6))
  3742.         typename += 6;
  3743.  
  3744.       for (ppt = file_symbols; ppt; ppt = ppt->next)
  3745.         for (i = 0; i < ppt->nsyms; i++)
  3746.           {
  3747.         struct symbol *sym = ppt->symbol[i];
  3748.  
  3749.         if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
  3750.             && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
  3751.             && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
  3752.             TYPE_CODE (*type))
  3753.             && !strcmp (SYMBOL_NAME (sym), typename))
  3754.           bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type));
  3755.           }
  3756.     }
  3757.       else
  3758.     /* It has been defined; don't mark it as a stub.  */
  3759.     TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
  3760.     }
  3761.   undef_types_length = 0;
  3762. }
  3763.  
  3764. /* Skip rest of this symbol and return an error type.
  3765.  
  3766.    General notes on error recovery:  error_type always skips to the
  3767.    end of the symbol (modulo cretinous dbx symbol name continuation).
  3768.    Thus code like this:
  3769.  
  3770.    if (*(*pp)++ != ';')
  3771.      return error_type (pp);
  3772.  
  3773.    is wrong because if *pp starts out pointing at '\0' (typically as the
  3774.    result of an earlier error), it will be incremented to point to the
  3775.    start of the next symbol, which might produce strange results, at least
  3776.    if you run off the end of the string table.  Instead use
  3777.  
  3778.    if (**pp != ';')
  3779.      return error_type (pp);
  3780.    ++*pp;
  3781.  
  3782.    or
  3783.  
  3784.    if (**pp != ';')
  3785.      foo = error_type (pp);
  3786.    else
  3787.      ++*pp;
  3788.  
  3789.    And in case it isn't obvious, the point of all this hair is so the compiler
  3790.    can define new types and new syntaxes, and old versions of the
  3791.    debugger will be able to read the new symbol tables.  */
  3792.  
  3793. static struct type *
  3794. error_type (pp)
  3795.      char **pp;
  3796. {
  3797.   complain (&error_type_complaint, 0);
  3798.   while (1)
  3799.     {
  3800.       /* Skip to end of symbol.  */
  3801.       while (**pp != '\0')
  3802.     (*pp)++;
  3803.  
  3804.       /* Check for and handle cretinous dbx symbol name continuation!  */
  3805.       if ((*pp)[-1] == '\\')
  3806.     *pp = next_symbol_text ();
  3807.       else
  3808.     break;
  3809.     }
  3810.   return builtin_type_error;
  3811. }
  3812.  
  3813. /* Read a dbx type reference or definition;
  3814.    return the type that is meant.
  3815.    This can be just a number, in which case it references
  3816.    a type already defined and placed in type_vector.
  3817.    Or the number can be followed by an =, in which case
  3818.    it means to define a new type according to the text that
  3819.    follows the =.  */
  3820.  
  3821. static
  3822. struct type *
  3823. read_type (pp)
  3824.      register char **pp;
  3825. {
  3826.   register struct type *type = 0;
  3827.   struct type *type1;
  3828.   int typenums[2];
  3829.   int xtypenums[2];
  3830.  
  3831.   /* Read type number if present.  The type number may be omitted.
  3832.      for instance in a two-dimensional array declared with type
  3833.      "ar1;1;10;ar1;1;10;4".  */
  3834.   if ((**pp >= '0' && **pp <= '9')
  3835.       || **pp == '(')
  3836.     {
  3837.       read_type_number (pp, typenums);
  3838.       
  3839.       /* Detect random reference to type not yet defined.
  3840.      Allocate a type object but leave it zeroed.  */
  3841.       if (**pp != '=')
  3842.     return dbx_alloc_type (typenums);
  3843.  
  3844.       *pp += 2;
  3845.     }
  3846.   else
  3847.     {
  3848.       /* 'typenums=' not present, type is anonymous.  Read and return
  3849.      the definition, but don't put it in the type vector.  */
  3850.       typenums[0] = typenums[1] = -1;
  3851.       *pp += 1;
  3852.     }
  3853.       
  3854.   switch ((*pp)[-1])
  3855.     {
  3856.     case 'x':
  3857.       {
  3858.     enum type_code code;
  3859.  
  3860.     /* Used to index through file_symbols.  */
  3861.     struct pending *ppt;
  3862.     int i;
  3863.     
  3864.     /* Name including "struct", etc.  */
  3865.     char *type_name;
  3866.     
  3867.     /* Name without "struct", etc.  */
  3868.     char *type_name_only;
  3869.  
  3870.     {
  3871.       char *prefix;
  3872.       char *from, *to;
  3873.       
  3874.       /* Set the type code according to the following letter.  */
  3875.       switch ((*pp)[0])
  3876.         {
  3877.         case 's':
  3878.           code = TYPE_CODE_STRUCT;
  3879.           prefix = "struct ";
  3880.           break;
  3881.         case 'u':
  3882.           code = TYPE_CODE_UNION;
  3883.           prefix = "union ";
  3884.           break;
  3885.         case 'e':
  3886.           code = TYPE_CODE_ENUM;
  3887.           prefix = "enum ";
  3888.           break;
  3889.         default:
  3890.           return error_type (pp);
  3891.         }
  3892.       
  3893.       to = type_name = (char *)
  3894.         obstack_alloc (symbol_obstack,
  3895.                (strlen (prefix) +
  3896.                 ((char *) strchr (*pp, ':') - (*pp)) + 1));
  3897.     
  3898.       /* Copy the prefix.  */
  3899.       from = prefix;
  3900.       while (*to++ = *from++)
  3901.         ;
  3902.       to--; 
  3903.     
  3904.       type_name_only = to;
  3905.  
  3906.       /* Copy the name.  */
  3907.       from = *pp + 1;
  3908.       while ((*to++ = *from++) != ':')
  3909.         ;
  3910.       *--to = '\0';
  3911.       
  3912.       /* Set the pointer ahead of the name which we just read.  */
  3913.       *pp = from;
  3914.     
  3915. #if 0
  3916.       /* The following hack is clearly wrong, because it doesn't
  3917.          check whether we are in a baseclass.  I tried to reproduce
  3918.          the case that it is trying to fix, but I couldn't get
  3919.          g++ to put out a cross reference to a basetype.  Perhaps
  3920.          it doesn't do it anymore.  */
  3921.       /* Note: for C++, the cross reference may be to a base type which
  3922.          has not yet been seen.  In this case, we skip to the comma,
  3923.          which will mark the end of the base class name.  (The ':'
  3924.          at the end of the base class name will be skipped as well.)
  3925.          But sometimes (ie. when the cross ref is the last thing on
  3926.          the line) there will be no ','.  */
  3927.       from = (char *) strchr (*pp, ',');
  3928.       if (from)
  3929.         *pp = from;
  3930. #endif /* 0 */
  3931.     }
  3932.  
  3933.     /* Now check to see whether the type has already been declared.  */
  3934.     /* This is necessary at least in the case where the
  3935.        program says something like
  3936.          struct foo bar[5];
  3937.        The compiler puts out a cross-reference; we better find
  3938.        set the length of the structure correctly so we can
  3939.        set the length of the array.  */
  3940.     for (ppt = file_symbols; ppt; ppt = ppt->next)
  3941.       for (i = 0; i < ppt->nsyms; i++)
  3942.         {
  3943.           struct symbol *sym = ppt->symbol[i];
  3944.  
  3945.           if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
  3946.           && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
  3947.           && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
  3948.           && !strcmp (SYMBOL_NAME (sym), type_name_only))
  3949.         {
  3950.           obstack_free (symbol_obstack, type_name);
  3951.           type = SYMBOL_TYPE (sym);
  3952.           return type;
  3953.         }
  3954.         }
  3955.     
  3956.     /* Didn't find the type to which this refers, so we must
  3957.        be dealing with a forward reference.  Allocate a type
  3958.        structure for it, and keep track of it so we can
  3959.        fill in the rest of the fields when we get the full
  3960.        type.  */
  3961.     type = dbx_alloc_type (typenums);
  3962.     TYPE_CODE (type) = code;
  3963.     TYPE_NAME (type) = type_name;
  3964.  
  3965.     TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
  3966.  
  3967.     add_undefined_type (type);
  3968.     return type;
  3969.       }
  3970.  
  3971.     case '0':
  3972.     case '1':
  3973.     case '2':
  3974.     case '3':
  3975.     case '4':
  3976.     case '5':
  3977.     case '6':
  3978.     case '7':
  3979.     case '8':
  3980.     case '9':
  3981.     case '(':
  3982.       (*pp)--;
  3983.       read_type_number (pp, xtypenums);
  3984.       type = *dbx_lookup_type (xtypenums);
  3985.       if (type == 0)
  3986.     type = builtin_type_void;
  3987.       if (typenums[0] != -1)
  3988.     *dbx_lookup_type (typenums) = type;
  3989.       break;
  3990.  
  3991.     case '*':
  3992.       type1 = read_type (pp);
  3993.       type = lookup_pointer_type (type1);
  3994.       if (typenums[0] != -1)
  3995.     *dbx_lookup_type (typenums) = type;
  3996.       break;
  3997.  
  3998.     case '@':
  3999.       {
  4000.     struct type *domain = read_type (pp);
  4001.     struct type *memtype;
  4002.  
  4003.     if (**pp != ',')
  4004.       /* Invalid member type data format.  */
  4005.       return error_type (pp);
  4006.     ++*pp;
  4007.  
  4008.     memtype = read_type (pp);
  4009.     type = dbx_alloc_type (typenums);
  4010.     smash_to_member_type (type, domain, memtype);
  4011.       }
  4012.       break;
  4013.  
  4014.     case '#':
  4015.       if ((*pp)[0] == '#')
  4016.     {
  4017.       /* We'll get the parameter types from the name.  */
  4018.       struct type *return_type;
  4019.  
  4020.       *pp += 1;
  4021.       return_type = read_type (pp);
  4022.       if (*(*pp)++ != ';')
  4023.         complain (&invalid_member_complaint, symnum);
  4024.       type = allocate_stub_method (return_type);
  4025.       if (typenums[0] != -1)
  4026.         *dbx_lookup_type (typenums) = type;
  4027.     }
  4028.       else
  4029.     {
  4030.       struct type *domain = read_type (pp);
  4031.       struct type *return_type;
  4032.       struct type **args;
  4033.  
  4034.       if (*(*pp)++ != ',')
  4035.         error ("invalid member type data format, at symtab pos %d.",
  4036.            symnum);
  4037.  
  4038.       return_type = read_type (pp);
  4039.       args = read_args (pp, ';');
  4040.       type = dbx_alloc_type (typenums);
  4041.       smash_to_method_type (type, domain, return_type, args);
  4042.     }
  4043.       break;
  4044.  
  4045.     case '&':
  4046.       type1 = read_type (pp);
  4047.       type = lookup_reference_type (type1);
  4048.       if (typenums[0] != -1)
  4049.     *dbx_lookup_type (typenums) = type;
  4050.       break;
  4051.  
  4052.     case 'f':
  4053.       type1 = read_type (pp);
  4054.       type = lookup_function_type (type1);
  4055.       if (typenums[0] != -1)
  4056.     *dbx_lookup_type (typenums) = type;
  4057.       break;
  4058.  
  4059.     case 'r':
  4060.       type = read_range_type (pp, typenums);
  4061.       if (typenums[0] != -1)
  4062.     *dbx_lookup_type (typenums) = type;
  4063.       break;
  4064.  
  4065.     case 'e':
  4066.       type = dbx_alloc_type (typenums);
  4067.       type = read_enum_type (pp, type);
  4068.       *dbx_lookup_type (typenums) = type;
  4069.       break;
  4070.  
  4071.     case 's':
  4072.       type = dbx_alloc_type (typenums);
  4073.       TYPE_NAME (type) = type_synonym_name;
  4074.       type_synonym_name = 0;
  4075.       type = read_struct_type (pp, type);
  4076.       break;
  4077.  
  4078.     case 'u':
  4079.       type = dbx_alloc_type (typenums);
  4080.       TYPE_NAME (type) = type_synonym_name;
  4081.       type_synonym_name = 0;
  4082.       type = read_struct_type (pp, type);
  4083.       TYPE_CODE (type) = TYPE_CODE_UNION;
  4084.       break;
  4085.  
  4086.     case 'a':
  4087.       if (**pp != 'r')
  4088.     return error_type (pp);
  4089.       ++*pp;
  4090.       
  4091.       type = dbx_alloc_type (typenums);
  4092.       type = read_array_type (pp, type);
  4093.       break;
  4094.  
  4095.     default:
  4096.       --*pp;            /* Go back to the symbol in error */
  4097.                 /* Particularly important if it was \0! */
  4098.       return error_type (pp);
  4099.     }
  4100.  
  4101.   if (type == 0)
  4102.     abort ();
  4103.  
  4104. #if 0
  4105.   /* If this is an overriding temporary alteration for a header file's
  4106.      contents, and this type number is unknown in the global definition,
  4107.      put this type into the global definition at this type number.  */
  4108.   if (header_file_prev_index >= 0)
  4109.     {
  4110.       register struct type **tp
  4111.         = explicit_lookup_type (header_file_prev_index, typenums[1]);
  4112.       if (*tp == 0)
  4113.     *tp = type;
  4114.     }
  4115. #endif
  4116.   return type;
  4117. }
  4118.  
  4119. #if 0
  4120. /* This would be a good idea, but it doesn't really work.  The problem
  4121.    is that in order to get the virtual context for a particular type,
  4122.    you need to know the virtual info from all of its basetypes,
  4123.    and you need to have processed its methods.  Since GDB reads
  4124.    symbols on a file-by-file basis, this means processing the symbols
  4125.    of all the files that are needed for each baseclass, which
  4126.    means potentially reading in all the debugging info just to fill
  4127.    in information we may never need.  */
  4128.  
  4129. /* This page contains subroutines of read_type.  */
  4130.  
  4131. /* FOR_TYPE is a struct type defining a virtual function NAME with type
  4132.    FN_TYPE.  The `virtual context' for this virtual function is the
  4133.    first base class of FOR_TYPE in which NAME is defined with signature
  4134.    matching FN_TYPE.  OFFSET serves as a hash on matches here.
  4135.  
  4136.    TYPE is the current type in which we are searching.  */
  4137.  
  4138. static struct type *
  4139. virtual_context (for_type, type, name, fn_type, offset)
  4140.      struct type *for_type, *type;
  4141.      char *name;
  4142.      struct type *fn_type;
  4143.      int offset;
  4144. {
  4145.   struct type *basetype = 0;
  4146.   int i;
  4147.  
  4148.   if (for_type != type)
  4149.     {
  4150.       /* Check the methods of TYPE.  */
  4151.       /* Need to do a check_stub_type here, but that breaks
  4152.      things because we can get infinite regress.  */
  4153.       for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
  4154.     if (!strcmp (TYPE_FN_FIELDLIST_NAME (type, i), name))
  4155.       break;
  4156.       if (i >= 0)
  4157.     {
  4158.       int j = TYPE_FN_FIELDLIST_LENGTH (type, i);
  4159.       struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  4160.  
  4161.       while (--j >= 0)
  4162.         if (TYPE_FN_FIELD_VOFFSET (f, j) == offset-1)
  4163.           return TYPE_FN_FIELD_FCONTEXT (f, j);
  4164.     }
  4165.     }
  4166.   for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
  4167.     {
  4168.       basetype = virtual_context (for_type, TYPE_BASECLASS (type, i), name,
  4169.                   fn_type, offset);
  4170.       if (basetype != for_type)
  4171.     return basetype;
  4172.     }
  4173.   return for_type;
  4174. }
  4175. #endif
  4176.  
  4177. /* Read the description of a structure (or union type)
  4178.    and return an object describing the type.  */
  4179.  
  4180. static struct type *
  4181. read_struct_type (pp, type)
  4182.      char **pp;
  4183.      register struct type *type;
  4184. {
  4185.   /* Total number of methods defined in this class.
  4186.      If the class defines two `f' methods, and one `g' method,
  4187.      then this will have the value 3.  */
  4188.   int total_length = 0;
  4189.  
  4190.   struct nextfield
  4191.     {
  4192.       struct nextfield *next;
  4193.       int visibility;            /* 0=public, 1=protected, 2=public */
  4194.       struct field field;
  4195.     };
  4196.  
  4197.   struct next_fnfield
  4198.     {
  4199.       struct next_fnfield *next;
  4200.       int visibility;            /* 0=public, 1=protected, 2=public */
  4201.       struct fn_field fn_field;
  4202.     };
  4203.  
  4204.   struct next_fnfieldlist
  4205.     {
  4206.       struct next_fnfieldlist *next;
  4207.       struct fn_fieldlist fn_fieldlist;
  4208.     };
  4209.  
  4210.   register struct nextfield *list = 0;
  4211.   struct nextfield *new;
  4212.   register char *p;
  4213.   int nfields = 0;
  4214.   register int n;
  4215.  
  4216.   register struct next_fnfieldlist *mainlist = 0;
  4217.   int nfn_fields = 0;
  4218.  
  4219.   if (TYPE_MAIN_VARIANT (type) == 0)
  4220.     {
  4221.       TYPE_MAIN_VARIANT (type) = type;
  4222.     }
  4223.  
  4224.   TYPE_CODE (type) = TYPE_CODE_STRUCT;
  4225.  
  4226.   /* First comes the total size in bytes.  */
  4227.  
  4228.   TYPE_LENGTH (type) = read_number (pp, 0);
  4229.  
  4230.   /* C++: Now, if the class is a derived class, then the next character
  4231.      will be a '!', followed by the number of base classes derived from.
  4232.      Each element in the list contains visibility information,
  4233.      the offset of this base class in the derived structure,
  4234.      and then the base type. */
  4235.   if (**pp == '!')
  4236.     {
  4237.       int i, n_baseclasses, offset;
  4238.       struct type *baseclass;
  4239.       int via_public;
  4240.  
  4241.       /* Nonzero if it is a virtual baseclass, i.e.,
  4242.  
  4243.      struct A{};
  4244.      struct B{};
  4245.      struct C : public B, public virtual A {};
  4246.  
  4247.      B is a baseclass of C; A is a virtual baseclass for C.  This is a C++
  4248.      2.0 language feature.  */
  4249.       int via_virtual;
  4250.  
  4251.       *pp += 1;
  4252.  
  4253.       n_baseclasses = read_number (pp, ',');
  4254.       TYPE_FIELD_VIRTUAL_BITS (type) =
  4255.       (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (n_baseclasses));
  4256.       B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
  4257.  
  4258.       for (i = 0; i < n_baseclasses; i++)
  4259.     {
  4260.       if (**pp == '\\')
  4261.         *pp = next_symbol_text ();
  4262.  
  4263.       switch (**pp)
  4264.         {
  4265.         case '0':
  4266.           via_virtual = 0;
  4267.           break;
  4268.         case '1':
  4269.           via_virtual = 1;
  4270.           break;
  4271.         default:
  4272.           /* Bad visibility format.  */
  4273.           return error_type (pp);
  4274.         }
  4275.       ++*pp;
  4276.  
  4277.       switch (**pp)
  4278.         {
  4279.         case '0':
  4280.           via_public = 0;
  4281.           break;
  4282.         case '2':
  4283.           via_public = 2;
  4284.           break;
  4285.         default:
  4286.           /* Bad visibility format.  */
  4287.           return error_type (pp);
  4288.         }
  4289.       if (via_virtual) 
  4290.         SET_TYPE_FIELD_VIRTUAL (type, i);
  4291.       ++*pp;
  4292.  
  4293.       /* Offset of the portion of the object corresponding to
  4294.          this baseclass.  Always zero in the absence of
  4295.          multiple inheritance.  */
  4296.       offset = read_number (pp, ',');
  4297.       baseclass = read_type (pp);
  4298.       *pp += 1;        /* skip trailing ';' */
  4299.  
  4300.       /* Make this baseclass visible for structure-printing purposes.  */
  4301.       new = (struct nextfield *) alloca (sizeof (struct nextfield));
  4302.       new->next = list;
  4303.       list = new;
  4304.       list->visibility = via_public;
  4305.       list->field.type = baseclass;
  4306.       list->field.name = type_name_no_tag (baseclass);
  4307.       list->field.bitpos = offset;
  4308.       list->field.bitsize = 0;    /* this should be an unpacked field! */
  4309.       nfields++;
  4310.     }
  4311.       TYPE_N_BASECLASSES (type) = n_baseclasses;
  4312.     }
  4313.  
  4314.   /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
  4315.      At the end, we see a semicolon instead of a field.
  4316.  
  4317.      In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
  4318.      a static field.
  4319.  
  4320.      The `?' is a placeholder for one of '/2' (public visibility),
  4321.      '/1' (protected visibility), '/0' (private visibility), or nothing
  4322.      (C style symbol table, public visibility).  */
  4323.  
  4324.   /* We better set p right now, in case there are no fields at all...    */
  4325.   p = *pp;
  4326.  
  4327.   while (**pp != ';')
  4328.     {
  4329.       /* Check for and handle cretinous dbx symbol name continuation!  */
  4330.       if (**pp == '\\') *pp = next_symbol_text ();
  4331.  
  4332.       /* Get space to record the next field's data.  */
  4333.       new = (struct nextfield *) alloca (sizeof (struct nextfield));
  4334.       new->next = list;
  4335.       list = new;
  4336.  
  4337.       /* Get the field name.  */
  4338.       p = *pp;
  4339.       if (*p == CPLUS_MARKER)
  4340.     {
  4341.       /* Special GNU C++ name.  */
  4342.       if (*++p == 'v')
  4343.         {
  4344.           const char *prefix;
  4345.           char *name = 0;
  4346.           struct type *context;
  4347.  
  4348.           switch (*++p)
  4349.         {
  4350.         case 'f':
  4351.           prefix = vptr_name;
  4352.           break;
  4353.         case 'b':
  4354.           prefix = vb_name;
  4355.           break;
  4356.         default:
  4357.           error ("invalid abbreviation at symtab pos %d.", symnum);
  4358.         }
  4359.           *pp = p + 1;
  4360.           context = read_type (pp);
  4361.           if (type_name_no_tag (context) == 0)
  4362.         {
  4363.           if (name == 0)
  4364.             error ("type name unknown at symtab pos %d.", symnum);
  4365.           /* FIXME-tiemann: when is `name' ever non-0?  */
  4366.           TYPE_NAME (context) = obsavestring (name, p - name - 1);
  4367.         }
  4368.           list->field.name = obconcat (prefix, type_name_no_tag (context), "");
  4369.           p = ++(*pp);
  4370.           if (p[-1] != ':')
  4371.         error ("invalid abbreviation at symtab pos %d.", symnum);
  4372.           list->field.type = read_type (pp);
  4373.           (*pp)++;            /* Skip the comma.  */
  4374.           list->field.bitpos = read_number (pp, ';');
  4375.           /* This field is unpacked.  */
  4376.           list->field.bitsize = 0;
  4377.         }
  4378.       /* GNU C++ anonymous type.  */
  4379.       else if (*p == '_')
  4380.         break;
  4381.       else
  4382.         error ("invalid abbreviation at symtab pos %d.", symnum);
  4383.  
  4384.       nfields++;
  4385.       continue;
  4386.     }
  4387.  
  4388.       while (*p != ':') p++;
  4389.       list->field.name = obsavestring (*pp, p - *pp);
  4390.  
  4391.       /* C++: Check to see if we have hit the methods yet.  */
  4392.       if (p[1] == ':')
  4393.     break;
  4394.  
  4395.       *pp = p + 1;
  4396.  
  4397.       /* This means we have a visibility for a field coming. */
  4398.       if (**pp == '/')
  4399.     {
  4400.       switch (*++*pp)
  4401.         {
  4402.         case '0':
  4403.           list->visibility = 0;    /* private */
  4404.           *pp += 1;
  4405.           break;
  4406.  
  4407.          case '1':
  4408.            list->visibility = 1;    /* protected */
  4409.            *pp += 1;
  4410.            break;
  4411.  
  4412.          case '2':
  4413.            list->visibility = 2;    /* public */
  4414.            *pp += 1;
  4415.            break;
  4416.          }
  4417.      }
  4418.        else /* normal dbx-style format.  */
  4419.     list->visibility = 2;        /* public */
  4420.  
  4421.       list->field.type = read_type (pp);
  4422.       if (**pp == ':')
  4423.      {
  4424.       /* Static class member.  */
  4425.        list->field.bitpos = (long)-1;
  4426.        p = ++(*pp);
  4427.        while (*p != ';') p++;
  4428.        list->field.bitsize = (long) savestring (*pp, p - *pp);
  4429.        *pp = p + 1;
  4430.        nfields++;
  4431.        continue;
  4432.      }
  4433.        else if (**pp != ',')
  4434.      /* Bad structure-type format.  */
  4435.      return error_type (pp);
  4436.  
  4437.       (*pp)++;            /* Skip the comma.  */
  4438.       list->field.bitpos = read_number (pp, ',');
  4439.       list->field.bitsize = read_number (pp, ';');
  4440.  
  4441. #if 0
  4442.       /* FIXME-tiemann: Can't the compiler put out something which
  4443.      lets us distinguish these? (or maybe just not put out anything
  4444.      for the field).  What is the story here?  What does the compiler
  4445.     really do?  Also, patch gdb.texinfo for this case; I document
  4446.     it as a possible problem there.  Search for "DBX-style".  */
  4447.  
  4448.       /* This is wrong because this is identical to the symbols
  4449.      produced for GCC 0-size arrays.  For example:
  4450.          typedef union {
  4451.        int num;
  4452.        char str[0];
  4453.      } foo;
  4454.      The code which dumped core in such circumstances should be
  4455.      fixed not to dump core.  */
  4456.  
  4457.       /* g++ -g0 can put out bitpos & bitsize zero for a static
  4458.      field.  This does not give us any way of getting its
  4459.      class, so we can't know its name.  But we can just
  4460.      ignore the field so we don't dump core and other nasty
  4461.      stuff.  */
  4462.       if (list->field.bitpos == 0
  4463.       && list->field.bitsize == 0)
  4464.     {
  4465.       complain (&dbx_class_complaint, 0);
  4466.       /* Ignore this field.  */
  4467.       list = list->next;
  4468.     }
  4469.       else
  4470. #endif /* 0 */
  4471.     {
  4472.       /* Detect an unpacked field and mark it as such.
  4473.          dbx gives a bit size for all fields.
  4474.          Note that forward refs cannot be packed,
  4475.          and treat enums as if they had the width of ints.  */
  4476.       if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
  4477.           && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
  4478.         list->field.bitsize = 0;
  4479.       if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
  4480.            || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
  4481.            && (list->field.bitsize
  4482.                == 8 * TYPE_LENGTH (builtin_type_int))
  4483.            )
  4484.            )
  4485.           &&
  4486.           list->field.bitpos % 8 == 0)
  4487.         list->field.bitsize = 0;
  4488.       nfields++;
  4489.     }
  4490.     }
  4491.  
  4492.   if (p[1] == ':')
  4493.     /* chill the list of fields: the last entry (at the head)
  4494.        is a partially constructed entry which we now scrub.  */
  4495.     list = list->next;
  4496.  
  4497.   /* Now create the vector of fields, and record how big it is.
  4498.      We need this info to record proper virtual function table information
  4499.      for this class's virtual functions.  */
  4500.  
  4501.   TYPE_NFIELDS (type) = nfields;
  4502.   TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
  4503.                            sizeof (struct field) * nfields);
  4504.  
  4505.   TYPE_FIELD_PRIVATE_BITS (type) =
  4506.     (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
  4507.   B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
  4508.  
  4509.   TYPE_FIELD_PROTECTED_BITS (type) =
  4510.     (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
  4511.   B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
  4512.  
  4513.   /* Copy the saved-up fields into the field vector.  */
  4514.  
  4515.   for (n = nfields; list; list = list->next)
  4516.     {
  4517.       n -= 1;
  4518.       TYPE_FIELD (type, n) = list->field;
  4519.       if (list->visibility == 0)
  4520.     SET_TYPE_FIELD_PRIVATE (type, n);
  4521.       else if (list->visibility == 1)
  4522.     SET_TYPE_FIELD_PROTECTED (type, n);
  4523.     }
  4524.  
  4525.   /* Now come the method fields, as NAME::methods
  4526.      where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
  4527.      At the end, we see a semicolon instead of a field.
  4528.  
  4529.      For the case of overloaded operators, the format is
  4530.      OPERATOR::*.methods, where OPERATOR is the string "operator",
  4531.      `*' holds the place for an operator name (such as `+=')
  4532.      and `.' marks the end of the operator name.  */
  4533.   if (p[1] == ':')
  4534.     {
  4535.       /* Now, read in the methods.  To simplify matters, we
  4536.      "unread" the name that has been read, so that we can
  4537.      start from the top.  */
  4538.  
  4539.       /* For each list of method lists... */
  4540.       do
  4541.     {
  4542.       int i;
  4543.       struct next_fnfield *sublist = 0;
  4544.       struct type *look_ahead_type = NULL;
  4545.       int length = 0;
  4546.       struct next_fnfieldlist *new_mainlist =
  4547.         (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
  4548.       char *main_fn_name;
  4549.  
  4550.       p = *pp;
  4551.  
  4552.       /* read in the name.  */
  4553.       while (*p != ':') p++;
  4554.       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
  4555.         {
  4556.           /* This lets the user type "break operator+".
  4557.              We could just put in "+" as the name, but that wouldn't
  4558.          work for "*".  */
  4559.           static char opname[32] = {'o', 'p', CPLUS_MARKER};
  4560.           char *o = opname + 3;
  4561.  
  4562.           /* Skip past '::'.  */
  4563.           p += 2;
  4564.           while (*p != '.')
  4565.         *o++ = *p++;
  4566.          main_fn_name = savestring (opname, o - opname);
  4567.           /* Skip past '.'  */
  4568.           *pp = p + 1;
  4569.         }
  4570.       else
  4571.         {
  4572.           i = 0;
  4573.           main_fn_name = savestring (*pp, p - *pp);
  4574.           /* Skip past '::'.  */
  4575.           *pp = p + 2;
  4576.         }
  4577.       new_mainlist->fn_fieldlist.name = main_fn_name;
  4578.  
  4579.       do
  4580.         {
  4581.           struct next_fnfield *new_sublist =
  4582.         (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
  4583.  
  4584.           /* Check for and handle cretinous dbx symbol name continuation!  */
  4585.           if (look_ahead_type == NULL) /* Normal case. */
  4586.         {
  4587.           if (**pp == '\\') *pp = next_symbol_text ();
  4588.  
  4589.           new_sublist->fn_field.type = read_type (pp);
  4590.           if (**pp != ':')
  4591.             /* Invalid symtab info for method.  */
  4592.             return error_type (pp);
  4593.             }
  4594.           else
  4595.         { /* g++ version 1 kludge */
  4596.           new_sublist->fn_field.type = look_ahead_type;
  4597.           look_ahead_type = NULL;
  4598.             }
  4599.  
  4600.           *pp += 1;
  4601.           p = *pp;
  4602.           while (*p != ';') p++;
  4603.           /* If this is just a stub, then we don't have the
  4604.          real name here.  */
  4605.           new_sublist->fn_field.physname = savestring (*pp, p - *pp);
  4606.           *pp = p + 1;
  4607.           new_sublist->visibility = *(*pp)++ - '0';
  4608.           if (**pp == '\\') *pp = next_symbol_text ();
  4609.           /* FIXME-tiemann: need to add const/volatile info
  4610.          to the methods.  For now, just skip the char.
  4611.          In future, here's what we need to implement:
  4612.  
  4613.          A for normal functions.
  4614.          B for `const' member functions.
  4615.          C for `volatile' member functions.
  4616.          D for `const volatile' member functions.  */
  4617.           if (**pp == 'A' || **pp == 'B' || **pp == 'C' || **pp == 'D')
  4618.             (*pp)++;
  4619.  
  4620.           /* This probably just means we're processing a file compiled
  4621.          with g++ version 1.  */
  4622.           else
  4623.             complain(&const_vol_complaint, **pp);
  4624.  
  4625.           switch (*(*pp)++)
  4626.         {
  4627.         case '*':
  4628.           /* virtual member function, followed by index.  */
  4629.           /* The sign bit is set to distinguish pointers-to-methods
  4630.              from virtual function indicies.  Since the array is
  4631.              in words, the quantity must be shifted left by 1
  4632.              on 16 bit machine, and by 2 on 32 bit machine, forcing
  4633.              the sign bit out, and usable as a valid index into
  4634.              the array.  Remove the sign bit here.  */
  4635.           new_sublist->fn_field.voffset =
  4636.               (0x7fffffff & read_number (pp, ';')) + 1;
  4637.  
  4638.           if (**pp == '\\') *pp = next_symbol_text ();
  4639.  
  4640.           if (**pp == ';' || **pp == '\0')
  4641.             /* Must be g++ version 1.  */
  4642.             new_sublist->fn_field.fcontext = 0;
  4643.           else
  4644.             {
  4645.               /* Figure out from whence this virtual function came.
  4646.              It may belong to virtual function table of
  4647.              one of its baseclasses.  */
  4648.               look_ahead_type = read_type (pp);
  4649.               if (**pp == ':')
  4650.             { /* g++ version 1 overloaded methods. */ }
  4651.               else
  4652.             {
  4653.               new_sublist->fn_field.fcontext = look_ahead_type;
  4654.               if (**pp != ';')
  4655.                 return error_type (pp);
  4656.               else
  4657.                 ++*pp;
  4658.               look_ahead_type = NULL;
  4659.                 }
  4660.             }
  4661.           break;
  4662.  
  4663.         case '?':
  4664.           /* static member function.  */
  4665.           new_sublist->fn_field.voffset = VOFFSET_STATIC;
  4666.           break;
  4667.         default:
  4668.           /* **pp == '.'.  */
  4669.           /* normal member function.  */
  4670.           new_sublist->fn_field.voffset = 0;
  4671.           new_sublist->fn_field.fcontext = 0;
  4672.           break;
  4673.         }
  4674.  
  4675.           new_sublist->next = sublist;
  4676.           sublist = new_sublist;
  4677.           length++;
  4678.         }
  4679.       while (**pp != ';' && **pp != '\0');
  4680.  
  4681.       *pp += 1;
  4682.  
  4683.       new_mainlist->fn_fieldlist.fn_fields =
  4684.         (struct fn_field *) obstack_alloc (symbol_obstack,
  4685.                            sizeof (struct fn_field) * length);
  4686.       TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
  4687.         (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
  4688.       B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist), length);
  4689.  
  4690.       TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
  4691.         (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
  4692.       B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist), length);
  4693.  
  4694.       for (i = length; (i--, sublist); sublist = sublist->next)
  4695.         {
  4696.           new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
  4697.           if (sublist->visibility == 0)
  4698.         B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
  4699.           else if (sublist->visibility == 1)
  4700.         B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
  4701.         }
  4702.  
  4703.       new_mainlist->fn_fieldlist.length = length;
  4704.       new_mainlist->next = mainlist;
  4705.       mainlist = new_mainlist;
  4706.       nfn_fields++;
  4707.       total_length += length;
  4708.     }
  4709.       while (**pp != ';');
  4710.     }
  4711.  
  4712.   *pp += 1;
  4713.  
  4714.   TYPE_FN_FIELDLISTS (type) =
  4715.     (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
  4716.                    sizeof (struct fn_fieldlist) * nfn_fields);
  4717.  
  4718.   TYPE_NFN_FIELDS (type) = nfn_fields;
  4719.   TYPE_NFN_FIELDS_TOTAL (type) = total_length;
  4720.  
  4721.   {
  4722.     int i;
  4723.     for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
  4724.       TYPE_NFN_FIELDS_TOTAL (type) +=
  4725.     TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
  4726.   }
  4727.  
  4728.   for (n = nfn_fields; mainlist; mainlist = mainlist->next)
  4729.     TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
  4730.  
  4731.   if (**pp == '~')
  4732.     {
  4733.       *pp += 1;
  4734.  
  4735.       if (**pp == '=')
  4736.     {
  4737.       TYPE_FLAGS (type)
  4738.         |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR;
  4739.       *pp += 1;
  4740.     }
  4741.       else if (**pp == '+')
  4742.     {
  4743.       TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR;
  4744.       *pp += 1;
  4745.     }
  4746.       else if (**pp == '-')
  4747.     {
  4748.       TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR;
  4749.       *pp += 1;
  4750.     }
  4751.  
  4752.       /* Read either a '%' or the final ';'.  */
  4753.       if (*(*pp)++ == '%')
  4754.     {
  4755.       /* Now we must record the virtual function table pointer's
  4756.          field information.  */
  4757.  
  4758.       struct type *t;
  4759.       int i;
  4760.  
  4761.       t = read_type (pp);
  4762.       p = (*pp)++;
  4763.       while (*p != '\0' && *p != ';')
  4764.         p++;
  4765.       if (*p == '\0')
  4766.         /* Premature end of symbol.  */
  4767.         return error_type (pp);
  4768.       
  4769.       TYPE_VPTR_BASETYPE (type) = t;
  4770.       if (type == t)
  4771.         {
  4772.           if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
  4773.         {
  4774.           /* FIXME-tiemann: what's this?  */
  4775. #if 0
  4776.           TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
  4777. #else
  4778.           error_type (pp);
  4779. #endif
  4780.         }
  4781.           else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
  4782.         if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name, 
  4783.             sizeof (vptr_name) -1))
  4784.           {
  4785.             TYPE_VPTR_FIELDNO (type) = i;
  4786.             break;
  4787.           }
  4788.           if (i < 0)
  4789.         /* Virtual function table field not found.  */
  4790.         return error_type (pp);
  4791.         }
  4792.       else
  4793.         TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
  4794.       *pp = p + 1;
  4795.     }
  4796.     }
  4797.  
  4798.   return type;
  4799. }
  4800.  
  4801. /* Read a definition of an array type,
  4802.    and create and return a suitable type object.
  4803.    Also creates a range type which represents the bounds of that
  4804.    array.  */
  4805. static struct type *
  4806. read_array_type (pp, type)
  4807.      register char **pp;
  4808.      register struct type *type;
  4809. {
  4810.   struct type *index_type, *element_type, *range_type;
  4811.   int lower, upper;
  4812.   int adjustable = 0;
  4813.  
  4814.   /* Format of an array type:
  4815.      "ar<index type>;lower;upper;<array_contents_type>".  Put code in
  4816.      to handle this.
  4817.  
  4818.      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
  4819.      for these, produce a type like float[][].  */
  4820.  
  4821.   index_type = read_type (pp);
  4822.   if (**pp != ';')
  4823.     /* Improper format of array type decl.  */
  4824.     return error_type (pp);
  4825.   ++*pp;
  4826.  
  4827.   if (!(**pp >= '0' && **pp <= '9'))
  4828.     {
  4829.       *pp += 1;
  4830.       adjustable = 1;
  4831.     }
  4832.   lower = read_number (pp, ';');
  4833.  
  4834.   if (!(**pp >= '0' && **pp <= '9'))
  4835.     {
  4836.       *pp += 1;
  4837.       adjustable = 1;
  4838.     }
  4839.   upper = read_number (pp, ';');
  4840.   
  4841.   element_type = read_type (pp);
  4842.  
  4843.   if (adjustable)
  4844.     {
  4845.       lower = 0;
  4846.       upper = -1;
  4847.     }
  4848.  
  4849.   {
  4850.     /* Create range type.  */
  4851.     range_type = (struct type *) obstack_alloc (symbol_obstack,
  4852.                         sizeof (struct type));
  4853.     TYPE_CODE (range_type) = TYPE_CODE_RANGE;
  4854.     TYPE_TARGET_TYPE (range_type) = index_type;
  4855.  
  4856.     /* This should never be needed.  */
  4857.     TYPE_LENGTH (range_type) = sizeof (int);
  4858.  
  4859.     TYPE_NFIELDS (range_type) = 2;
  4860.     TYPE_FIELDS (range_type) =
  4861.       (struct field *) obstack_alloc (symbol_obstack,
  4862.                       2 * sizeof (struct field));
  4863.     TYPE_FIELD_BITPOS (range_type, 0) = lower;
  4864.     TYPE_FIELD_BITPOS (range_type, 1) = upper;
  4865.   }
  4866.  
  4867.   TYPE_CODE (type) = TYPE_CODE_ARRAY;
  4868.   TYPE_TARGET_TYPE (type) = element_type;
  4869.   TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
  4870.   TYPE_NFIELDS (type) = 1;
  4871.   TYPE_FIELDS (type) =
  4872.     (struct field *) obstack_alloc (symbol_obstack,
  4873.                     sizeof (struct field));
  4874.   TYPE_FIELD_TYPE (type, 0) = range_type;
  4875.  
  4876.   return type;
  4877. }
  4878.  
  4879.  
  4880. /* Read a definition of an enumeration type,
  4881.    and create and return a suitable type object.
  4882.    Also defines the symbols that represent the values of the type.  */
  4883.  
  4884. static struct type *
  4885. read_enum_type (pp, type)
  4886.      register char **pp;
  4887.      register struct type *type;
  4888. {
  4889.   register char *p;
  4890.   char *name;
  4891.   register long n;
  4892.   register struct symbol *sym;
  4893.   int nsyms = 0;
  4894.   struct pending **symlist;
  4895.   struct pending *osyms, *syms;
  4896.   int o_nsyms;
  4897.  
  4898.   if (within_function)
  4899.     symlist = &local_symbols;
  4900.   else
  4901.     symlist = &file_symbols;
  4902.   osyms = *symlist;
  4903.   o_nsyms = osyms ? osyms->nsyms : 0;
  4904.  
  4905.   /* Read the value-names and their values.
  4906.      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
  4907.      A semicolon or comman instead of a NAME means the end.  */
  4908.   while (**pp && **pp != ';' && **pp != ',')
  4909.     {
  4910.       /* Check for and handle cretinous dbx symbol name continuation!  */
  4911.       if (**pp == '\\')    *pp = next_symbol_text ();
  4912.  
  4913.       p = *pp;
  4914.       while (*p != ':') p++;
  4915.       name = obsavestring (*pp, p - *pp);
  4916.       *pp = p + 1;
  4917.       n = read_number (pp, ',');
  4918.  
  4919.       sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
  4920.       bzero (sym, sizeof (struct symbol));
  4921.       SYMBOL_NAME (sym) = name;
  4922.       SYMBOL_CLASS (sym) = LOC_CONST;
  4923.       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
  4924.       SYMBOL_VALUE (sym) = n;
  4925.       add_symbol_to_list (sym, symlist);
  4926.       nsyms++;
  4927.     }
  4928.  
  4929.   if (**pp == ';')
  4930.     (*pp)++;            /* Skip the semicolon.  */
  4931.  
  4932.   /* Now fill in the fields of the type-structure.  */
  4933.  
  4934.   TYPE_LENGTH (type) = sizeof (int);
  4935.   TYPE_CODE (type) = TYPE_CODE_ENUM;
  4936.   TYPE_NFIELDS (type) = nsyms;
  4937.   TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
  4938.  
  4939.   /* Find the symbols for the values and put them into the type.
  4940.      The symbols can be found in the symlist that we put them on
  4941.      to cause them to be defined.  osyms contains the old value
  4942.      of that symlist; everything up to there was defined by us.  */
  4943.   /* Note that we preserve the order of the enum constants, so
  4944.      that in something like "enum {FOO, LAST_THING=FOO}" we print
  4945.      FOO, not LAST_THING.  */
  4946.  
  4947.   for (syms = *symlist, n = 0; syms; syms = syms->next)
  4948.     {
  4949.       int j = 0;
  4950.       if (syms == osyms)
  4951.     j = o_nsyms;
  4952.       for (; j < syms->nsyms; j++,n++)
  4953.     {
  4954.       struct symbol *xsym = syms->symbol[j];
  4955.       SYMBOL_TYPE (xsym) = type;
  4956.       TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
  4957.       TYPE_FIELD_VALUE (type, n) = 0;
  4958.       TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
  4959.       TYPE_FIELD_BITSIZE (type, n) = 0;
  4960.     }
  4961.       if (syms == osyms)
  4962.     break;
  4963.     }
  4964.  
  4965. #if 0
  4966.   /* This screws up perfectly good C programs with enums.  FIXME.  */
  4967.   /* Is this Modula-2's BOOLEAN type?  Flag it as such if so. */
  4968.   if(TYPE_NFIELDS(type) == 2 &&
  4969.      ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
  4970.        !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
  4971.       (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
  4972.        !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
  4973.      TYPE_CODE(type) = TYPE_CODE_BOOL;
  4974. #endif
  4975.  
  4976.   return type;
  4977. }
  4978.  
  4979. /* Read a number from the string pointed to by *PP.
  4980.    The value of *PP is advanced over the number.
  4981.    If END is nonzero, the character that ends the
  4982.    number must match END, or an error happens;
  4983.    and that character is skipped if it does match.
  4984.    If END is zero, *PP is left pointing to that character.
  4985.  
  4986.    If the number fits in a long, set *VALUE and set *BITS to 0.
  4987.    If not, set *BITS to be the number of bits in the number.
  4988.  
  4989.    If encounter garbage, set *BITS to -1.  */
  4990.  
  4991. static void
  4992. read_huge_number (pp, end, valu, bits)
  4993.      char **pp;
  4994.      int end;
  4995.      long *valu;
  4996.      int *bits;
  4997. {
  4998.   char *p = *pp;
  4999.   int sign = 1;
  5000.   long n = 0;
  5001.   int radix = 10;
  5002.   char overflow = 0;
  5003.   int nbits = 0;
  5004.   int c;
  5005.   long upper_limit;
  5006.   
  5007.   if (*p == '-')
  5008.     {
  5009.       sign = -1;
  5010.       p++;
  5011.     }
  5012.  
  5013.   /* Leading zero means octal.  GCC uses this to output values larger
  5014.      than an int (because that would be hard in decimal).  */
  5015.   if (*p == '0')
  5016.     {
  5017.       radix = 8;
  5018.       p++;
  5019.     }
  5020.  
  5021.   upper_limit = LONG_MAX / radix;
  5022.   while ((c = *p++) >= '0' && c <= ('0' + radix))
  5023.     {
  5024.       if (n <= upper_limit)
  5025.     {
  5026.       n *= radix;
  5027.       n += c - '0';        /* FIXME this overflows anyway */
  5028.     }
  5029.       else
  5030.     overflow = 1;
  5031.       
  5032.       /* This depends on large values being output in octal, which is
  5033.      what GCC does. */
  5034.       if (radix == 8)
  5035.     {
  5036.       if (nbits == 0)
  5037.         {
  5038.           if (c == '0')
  5039.         /* Ignore leading zeroes.  */
  5040.         ;
  5041.           else if (c == '1')
  5042.         nbits = 1;
  5043.           else if (c == '2' || c == '3')
  5044.         nbits = 2;
  5045.           else
  5046.         nbits = 3;
  5047.         }
  5048.       else
  5049.         nbits += 3;
  5050.     }
  5051.     }
  5052.   if (end)
  5053.     {
  5054.       if (c && c != end)
  5055.     {
  5056.       if (bits != NULL)
  5057.         *bits = -1;
  5058.       return;
  5059.     }
  5060.     }
  5061.   else
  5062.     --p;
  5063.  
  5064.   *pp = p;
  5065.   if (overflow)
  5066.     {
  5067.       if (nbits == 0)
  5068.     {
  5069.       /* Large decimal constants are an error (because it is hard to
  5070.          count how many bits are in them).  */
  5071.       if (bits != NULL)
  5072.         *bits = -1;
  5073.       return;
  5074.     }
  5075.       
  5076.       /* -0x7f is the same as 0x80.  So deal with it by adding one to
  5077.      the number of bits.  */
  5078.       if (sign == -1)
  5079.     ++nbits;
  5080.       if (bits)
  5081.     *bits = nbits;
  5082.     }
  5083.   else
  5084.     {
  5085.       if (valu)
  5086.     *valu = n * sign;
  5087.       if (bits)
  5088.     *bits = 0;
  5089.     }
  5090. }
  5091.  
  5092. #define    MAX_OF_C_TYPE(t)    ((1 << (sizeof (t)*8 - 1)) - 1)
  5093. #define MIN_OF_C_TYPE(t)    (-(1 << (sizeof (t)*8 - 1)))
  5094.  
  5095. static struct type *
  5096. read_range_type (pp, typenums)
  5097.      char **pp;
  5098.      int typenums[2];
  5099. {
  5100.   int rangenums[2];
  5101.   long n2, n3;
  5102.   int n2bits, n3bits;
  5103.   int self_subrange;
  5104.   struct type *result_type;
  5105.  
  5106.   /* First comes a type we are a subrange of.
  5107.      In C it is usually 0, 1 or the type being defined.  */
  5108.   read_type_number (pp, rangenums);
  5109.   self_subrange = (rangenums[0] == typenums[0] &&
  5110.            rangenums[1] == typenums[1]);
  5111.  
  5112.   /* A semicolon should now follow; skip it.  */
  5113.   if (**pp == ';')
  5114.     (*pp)++;
  5115.  
  5116.   /* The remaining two operands are usually lower and upper bounds
  5117.      of the range.  But in some special cases they mean something else.  */
  5118.   read_huge_number (pp, ';', &n2, &n2bits);
  5119.   read_huge_number (pp, ';', &n3, &n3bits);
  5120.  
  5121.   if (n2bits == -1 || n3bits == -1)
  5122.     return error_type (pp);
  5123.   
  5124.   /* If limits are huge, must be large integral type.  */
  5125.   if (n2bits != 0 || n3bits != 0)
  5126.     {
  5127.       char got_signed = 0;
  5128.       char got_unsigned = 0;
  5129.       /* Number of bits in the type.  */
  5130.       int nbits;
  5131.  
  5132.       /* Range from 0 to <large number> is an unsigned large integral type.  */
  5133.       if ((n2bits == 0 && n2 == 0) && n3bits != 0)
  5134.     {
  5135.       got_unsigned = 1;
  5136.       nbits = n3bits;
  5137.     }
  5138.       /* Range from <large number> to <large number>-1 is a large signed
  5139.      integral type.  */
  5140.       else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
  5141.     {
  5142.       got_signed = 1;
  5143.       nbits = n2bits;
  5144.     }
  5145.  
  5146.       /* Check for "long long".  */
  5147.       if (got_signed && nbits == TARGET_LONG_LONG_BIT)
  5148.     return builtin_type_long_long;
  5149.       if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
  5150.     return builtin_type_unsigned_long_long;
  5151.  
  5152.       if (got_signed || got_unsigned)
  5153.     {
  5154.       result_type = (struct type *) obstack_alloc (symbol_obstack,
  5155.                                sizeof (struct type));
  5156.       bzero (result_type, sizeof (struct type));
  5157.       TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
  5158.       TYPE_MAIN_VARIANT (result_type) = result_type;
  5159.       TYPE_CODE (result_type) = TYPE_CODE_INT;
  5160.       if (got_unsigned)
  5161.         TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
  5162.       return result_type;
  5163.     }
  5164.       else
  5165.     return error_type (pp);
  5166.     }
  5167.  
  5168.   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
  5169.   if (self_subrange && n2 == 0 && n3 == 0)
  5170.     return builtin_type_void;
  5171.  
  5172.   /* If n3 is zero and n2 is not, we want a floating type,
  5173.      and n2 is the width in bytes.
  5174.  
  5175.      Fortran programs appear to use this for complex types also,
  5176.      and they give no way to distinguish between double and single-complex!
  5177.      We don't have complex types, so we would lose on all fortran files!
  5178.      So return type `double' for all of those.  It won't work right
  5179.      for the complex values, but at least it makes the file loadable.  */
  5180.  
  5181.   if (n3 == 0 && n2 > 0)
  5182.     {
  5183.       if (n2 == sizeof (float))
  5184.     return builtin_type_float;
  5185.       return builtin_type_double;
  5186.     }
  5187.  
  5188.   /* If the upper bound is -1, it must really be an unsigned int.  */
  5189.  
  5190.   else if (n2 == 0 && n3 == -1)
  5191.     {
  5192.       if (sizeof (int) == sizeof (long))
  5193.     return builtin_type_unsigned_int;
  5194.       else
  5195.     return builtin_type_unsigned_long;
  5196.     }
  5197.  
  5198.   /* Special case: char is defined (Who knows why) as a subrange of
  5199.      itself with range 0-127.  */
  5200.   else if (self_subrange && n2 == 0 && n3 == 127)
  5201.     return builtin_type_char;
  5202.  
  5203.   /* Assumptions made here: Subrange of self is equivalent to subrange
  5204.      of int.  */
  5205.   else if (n2 == 0
  5206.        && (self_subrange ||
  5207.            *dbx_lookup_type (rangenums) == builtin_type_int))
  5208.     {
  5209.       /* an unsigned type */
  5210. #ifdef LONG_LONG
  5211.       if (n3 == - sizeof (long long))
  5212.     return builtin_type_unsigned_long_long;
  5213. #endif
  5214.       if (n3 == (unsigned int)~0L)
  5215.     return builtin_type_unsigned_int;
  5216.       if (n3 == (unsigned long)~0L)
  5217.     return builtin_type_unsigned_long;
  5218.       if (n3 == (unsigned short)~0L)
  5219.     return builtin_type_unsigned_short;
  5220.       if (n3 == (unsigned char)~0L)
  5221.     return builtin_type_unsigned_char;
  5222.     }
  5223. #ifdef LONG_LONG
  5224.   else if (n3 == 0 && n2 == -sizeof (long long))
  5225.     return builtin_type_long_long;
  5226. #endif  
  5227.   else if (n2 == -n3 -1)
  5228.     {
  5229.       /* a signed type */
  5230.       if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
  5231.     return builtin_type_int;
  5232.       if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
  5233.      return builtin_type_long;
  5234.       if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
  5235.     return builtin_type_short;
  5236.       if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
  5237.     return builtin_type_char;
  5238.     }
  5239.  
  5240.   /* We have a real range type on our hands.  Allocate space and
  5241.      return a real pointer.  */
  5242.  
  5243.   /* At this point I don't have the faintest idea how to deal with
  5244.      a self_subrange type; I'm going to assume that this is used
  5245.      as an idiom, and that all of them are special cases.  So . . .  */
  5246.   if (self_subrange)
  5247.     return error_type (pp);
  5248.  
  5249.   result_type = (struct type *) obstack_alloc (symbol_obstack,
  5250.                            sizeof (struct type));
  5251.   bzero (result_type, sizeof (struct type));
  5252.  
  5253.   TYPE_CODE (result_type) = TYPE_CODE_RANGE;
  5254.  
  5255.   TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
  5256.   if (TYPE_TARGET_TYPE (result_type) == 0) {
  5257.     complain (&range_type_base_complaint, rangenums[1]);
  5258.     TYPE_TARGET_TYPE (result_type) = builtin_type_int;
  5259.   }
  5260.  
  5261.   TYPE_NFIELDS (result_type) = 2;
  5262.   TYPE_FIELDS (result_type) =
  5263.      (struct field *) obstack_alloc (symbol_obstack,
  5264.                      2 * sizeof (struct field));
  5265.   bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
  5266.   TYPE_FIELD_BITPOS (result_type, 0) = n2;
  5267.   TYPE_FIELD_BITPOS (result_type, 1) = n3;
  5268.  
  5269. #if 0
  5270. /* Note that TYPE_LENGTH (result_type) is just overridden a few
  5271.    statements down.  What do we really need here?  */
  5272.   /* We have to figure out how many bytes it takes to hold this
  5273.      range type.  I'm going to assume that anything that is pushing
  5274.      the bounds of a long was taken care of above.  */
  5275.   if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char))
  5276.     TYPE_LENGTH (result_type) = 1;
  5277.   else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short))
  5278.     TYPE_LENGTH (result_type) = sizeof (short);
  5279.   else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int))
  5280.     TYPE_LENGTH (result_type) = sizeof (int);
  5281.   else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long))
  5282.     TYPE_LENGTH (result_type) = sizeof (long);
  5283.   else
  5284.     /* Ranged type doesn't fit within known sizes.  */
  5285.     /* FIXME -- use "long long" here.  */
  5286.     return error_type (pp);
  5287. #endif
  5288.  
  5289.   TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
  5290.  
  5291.   return result_type;
  5292. }
  5293.  
  5294. /* Read a number from the string pointed to by *PP.
  5295.    The value of *PP is advanced over the number.
  5296.    If END is nonzero, the character that ends the
  5297.    number must match END, or an error happens;
  5298.    and that character is skipped if it does match.
  5299.    If END is zero, *PP is left pointing to that character.  */
  5300.  
  5301. static long
  5302. read_number (pp, end)
  5303.      char **pp;
  5304.      int end;
  5305. {
  5306.   register char *p = *pp;
  5307.   register long n = 0;
  5308.   register int c;
  5309.   int sign = 1;
  5310.  
  5311.   /* Handle an optional leading minus sign.  */
  5312.  
  5313.   if (*p == '-')
  5314.     {
  5315.       sign = -1;
  5316.       p++;
  5317.     }
  5318.  
  5319.   /* Read the digits, as far as they go.  */
  5320.  
  5321.   while ((c = *p++) >= '0' && c <= '9')
  5322.     {
  5323.       n *= 10;
  5324.       n += c - '0';
  5325.     }
  5326.   if (end)
  5327.     {
  5328.       if (c && c != end)
  5329.     error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
  5330.     }
  5331.   else
  5332.     --p;
  5333.  
  5334.   *pp = p;
  5335.   return n * sign;
  5336. }
  5337.  
  5338. /* Read in an argument list.  This is a list of types, separated by commas
  5339.    and terminated with END.  Return the list of types read in, or (struct type
  5340.    **)-1 if there is an error.  */
  5341. static struct type **
  5342. read_args (pp, end)
  5343.      char **pp;
  5344.      int end;
  5345. {
  5346.   struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
  5347.   int n = 0;
  5348.  
  5349.   while (**pp != end)
  5350.     {
  5351.       if (**pp != ',')
  5352.     /* Invalid argument list: no ','.  */
  5353.     return (struct type **)-1;
  5354.       *pp += 1;
  5355.  
  5356.       /* Check for and handle cretinous dbx symbol name continuation! */
  5357.       if (**pp == '\\')
  5358.     *pp = next_symbol_text ();
  5359.  
  5360.       types[n++] = read_type (pp);
  5361.     }
  5362.   *pp += 1;            /* get past `end' (the ':' character) */
  5363.  
  5364.   if (n == 1)
  5365.     {
  5366.       rval = (struct type **) xmalloc (2 * sizeof (struct type *));
  5367.     }
  5368.   else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
  5369.     {
  5370.       rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
  5371.       bzero (rval + n, sizeof (struct type *));
  5372.     }
  5373.   else
  5374.     {
  5375.       rval = (struct type **) xmalloc (n * sizeof (struct type *));
  5376.     }
  5377.   bcopy (types, rval, n * sizeof (struct type *));
  5378.   return rval;
  5379. }
  5380.  
  5381. /* Copy a pending list, used to record the contents of a common
  5382.    block for later fixup.  */
  5383. static struct pending *
  5384. copy_pending (beg, begi, end)
  5385.     struct pending *beg, *end;
  5386.     int begi;
  5387. {
  5388.   struct pending *new = 0;
  5389.   struct pending *next;
  5390.  
  5391.   for (next = beg; next != 0 && (next != end || begi < end->nsyms);
  5392.        next = next->next, begi = 0)
  5393.     {
  5394.       register int j;
  5395.       for (j = begi; j < next->nsyms; j++)
  5396.     add_symbol_to_list (next->symbol[j], &new);
  5397.     }
  5398.   return new;
  5399. }
  5400.  
  5401. /* Add a common block's start address to the offset of each symbol
  5402.    declared to be in it (by being between a BCOMM/ECOMM pair that uses
  5403.    the common block name).  */
  5404.  
  5405. static void
  5406. fix_common_block (sym, valu)
  5407.     struct symbol *sym;
  5408.     int valu;
  5409. {
  5410.   struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
  5411.   for ( ; next; next = next->next)
  5412.     {
  5413.       register int j;
  5414.       for (j = next->nsyms - 1; j >= 0; j--)
  5415.     SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
  5416.     }
  5417. }
  5418.  
  5419. /* Register our willingness to decode symbols for SunOS and a.out and
  5420.    b.out files handled by BFD... */
  5421. static struct sym_fns sunos_sym_fns = {"sunOs", 6,
  5422.               dbx_new_init, dbx_symfile_init, dbx_symfile_read};
  5423.  
  5424. static struct sym_fns aout_sym_fns = {"a.out", 5,
  5425.               dbx_new_init, dbx_symfile_init, dbx_symfile_read};
  5426.  
  5427. static struct sym_fns bout_sym_fns = {"b.out", 5,
  5428.               dbx_new_init, dbx_symfile_init, dbx_symfile_read};
  5429.  
  5430. void
  5431. _initialize_dbxread ()
  5432. {
  5433.   add_symtab_fns(&sunos_sym_fns);
  5434.   add_symtab_fns(&aout_sym_fns);
  5435.   add_symtab_fns(&bout_sym_fns);
  5436.  
  5437.   undef_types_allocated = 20;
  5438.   undef_types_length = 0;
  5439.   undef_types = (struct type **) xmalloc (undef_types_allocated *
  5440.                       sizeof (struct type *));
  5441. }
  5442.